Jump to content

RegWrite to run chkdsk


Recommended Posts

Hey Friends,

I need your help to create a autoit script which will run chkdsk upon the next reboot. I have tried 4 different versions of available scripts but none work. I have listed them below. I am using the latest version of Autoit 3 for Jan 2019. I am running WIndows 10 home X64. UAC and antivirus are not the problem because i have them off temporarily until I get this script working. I have given Autoit x32 and X64 full control permissions. I will appreciate your help and advice. 

Failing scripts:

Not Working
RegWrite('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager' , 'BootExecute' , 'REG_MULTI_SZ' , 'autocheck autochk /r \??\C:')

Not Working
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager", "BootExecute", "REG_EXPAND_SZ", "autocheck autochk /r \??\C:")

Not Working
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager","BootExecute","REG_MULTI_SZ", "autocheck autochk /p \??\C:" & @LF & "autocheck autochk *" & @LF)

Not Working
Func OnReboot_CheckHardDrive()
    Local $str = 'autocheck autochk /p \??\C:' & @LF
    $str &= 'autocheck autochk *'
    ;
    Local $sKey = 'HKEY_LOCAL_MACHINE64\System\CurrentControlSet\Control\Session Manager'
    If @OSArch <> 'X64' Then $sKey = StringReplace($sKey, '64', '')
    RegWrite($sKey, 'BootExecute', 'REG_MULTI_SZ', $str)
    If @error Then Return SetError(-1, 0, -1)
EndFunc

Not Working
Func OnReboot_CheckHardDrive()
    Local $str = 'autocheck autochk /p ??C:' & @LF & 'autocheck autochk *'
    Local $sKey = 'HKEY_LOCAL_MACHINE64SystemCurrentControlSetControlSession Manager'
    If @OSArch <> 'X64' Then $sKey = StringReplace($sKey, '64', '')
    RegWrite($sKey, 'BootExecute', 'REG_MULTI_SZ', $str)
EndFunc

Thanks in advance!

 

Link to comment
Share on other sites

  • Moderators

"Not working" doesn't exactly tell us a whole lot. Is it not writing the registry values? Is it writing them but not executing the command? Is it doing something else altogether unexpected? Help us help you ;)

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

13 hours ago, JLogan3o13 said:

"Not working" doesn't exactly tell us a whole lot. Is it not writing the registry values? Is it writing them but not executing the command? Is it doing something else altogether unexpected? Help us help you ;)

 

It is not writing the registry values. There is no error message upon running the script.

Link to comment
Share on other sites

What credentials is the script running under? To modify that key it needs to be run as an administrator.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Did you include #RequireAdmin in the script, or specify the admin rights if running as a compile script?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

6 minutes ago, BrewManNH said:

Did you include #RequireAdmin in the script, or specify the admin rights if running as a compile script?

No, I did not. I do not want to use #RequireAdmin. Please tell me how I can specify the admin rights if running as a compile script.

Link to comment
Share on other sites

Why don't you want to use #RequireAdmin?

If you've downloaded the full version of Scite4AutoIt3 and not just the lite version that comes with AutoIt's download, you can add this to the script, #AutoIt3Wrapper_Res_requestedExecutionLevel, which writes to the program's manifest telling Windows that it requires elevation of the permissions needed for the program to run.

You'll still need to click the security warning to allow it to be executed.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

1 minute ago, BrewManNH said:

Why don't you want to use #RequireAdmin?

If you've downloaded the full version of Scite4AutoIt3 and not just the lite version that comes with AutoIt's download, you can add this to the script, #AutoIt3Wrapper_Res_requestedExecutionLevel, which writes to the program's manifest telling Windows that it requires elevation of the permissions needed for the program to run.

You'll still need to click the security warning to allow it to be executed.

I think that #RequireAdmin will trigger UAC. Is that correct?

If I use #AutoIt3Wrapper_Res_requestedExecutionLevel, will the user have to do anything when the script is run?

To provide you with some background for this project. I am creating a autoit maintenance script which will perform chkdsk /f on the next reboot. I do not want the user to get involved.

Will RunAs allow the script to run without user intervention?

Link to comment
Share on other sites

Are these computers on a domain, or are they standalone? If on a domain, you can remotely modify the registry from a computer where you have admin credentials if you have domain admin credentials. If not, then you will need to be running as an admin to modify that key. I haven't tried using RunAs this way, but you can always test it and let us know.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Just to help I will give 2 informations. 

 

In windows 10 you got 2 security option. 

First one is the EnableLUA that will trigger UAC at any security opération anyway. To make things easy let's say it is like "Admin rights"

But even with that you got the prompt of the UAC herself. It is called : ConsentPromptBehaviorAdmin in the registry.

So if you got admin rights Or EnableLUA turned OFF Or uac disabled. 

If ConsentPromptBehaviorAdmin is at 1 or 2 you will be prompt after a #requireadmin script.

The only thing I dont know is, how this is reacting with UAC enabled and promt disabled. It's like if you have One door after the other and you open only the second one. I guess you wont pass anyway :).

 

To help you more we need one information. 

We got the goal of your script but you dont specified. Why dont you want the conssent behaviur admin prompt.

You need to start the script and leave the computer? 

Or you want to run it from remote place ? 

What is the reason ?

 

22 hours ago, tomzardoz said:

I think that #RequireAdmin will trigger UAC. Is that correct?

So yes. This is true but only if : 

EnableLUA =1

AND/OR 

ConsentPromptBehaviorAdmin = 1or2

 

The second tips is : 

For any reason, you could :

-do your script with the admin prompt : (But that does not change anything for you since you have to start your script on the computer. it's like one more click ) 

-disable UAC and the prompt 

-do your needed stuff

-reboot or something if needed 

-Re enable UAC and prompt

With that order you can do your script with 2 click at the beginning. and nothing else.

 

@BrewManNH said a very good way for you if you dont want to do what i said. 

 

You can dodge the UAC by changing : 

EnableLUA =0

AND

ConsentPromptBehaviorAdmin = 0

From a remote computer: 

Win+R > Regedit > File > Connect to network registry > you add the computer name. And " VOILA ! "

 

Anyway both technique got a sad thing for you : You have to reboot. 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

I have tried adding #RequireAdmin and #AutoIt3Wrapper_Res_requestedExecutionLevel but cannot make any of the above scripts write to the registry. At this point I do not care about dodging UAC. I just want to get the script to run chkdsk on the next reboot. 

On this WIndows 10 Home computer, the user has admin rights and UAC has been turned off. I am not getting any errors in the Event Log and Autoit's SyntaxCheck Prod shows no errors either. 

Scripts tried:


RegWrite('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager' , 'BootExecute' , 'REG_MULTI_SZ' , 'autocheck autochk /r \??\C:')

_______________________
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager", "BootExecute", "REG_EXPAND_SZ", "autocheck autochk /r \??\C:")

________________________
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager","BootExecute","REG_MULTI_SZ", "autocheck autochk /p \??\C:" & @LF & "autocheck autochk *" & @LF)

_______________________
Func OnReboot_CheckHardDrive()
    Local $str = 'autocheck autochk /p \??\C:' & @LF
    $str &= 'autocheck autochk *'
    ;
    Local $sKey = 'HKEY_LOCAL_MACHINE64\System\CurrentControlSet\Control\Session Manager'
    If @OSArch <> 'X64' Then $sKey = StringReplace($sKey, '64', '')
    RegWrite($sKey, 'BootExecute', 'REG_MULTI_SZ', $str)
    If @error Then Return SetError(-1, 0, -1)
EndFunc

_______________________
Func OnReboot_CheckHardDrive()
    Local $str = 'autocheck autochk /p ??C:' & @LF & 'autocheck autochk *'
    Local $sKey = 'HKEY_LOCAL_MACHINE64SystemCurrentControlSetControlSession Manager'
    If @OSArch <> 'X64' Then $sKey = StringReplace($sKey, '64', '')
    RegWrite($sKey, 'BootExecute', 'REG_MULTI_SZ', $str)
EndFunc

_______________________

Link to comment
Share on other sites

The following works fine for me:

#RequireAdmin
Local $sRegRoot = @OSArch = "x64" ? "HKLM64" : "HKLM"
_RegWrite($sRegRoot & "\SYSTEM\CurrentControlSet\Control\Session Manager", "BootExecute", "REG_MULTI_SZ", "autocheck autochk /r \??\C:")

Func _RegWrite($_sKeyName, $_sValueName, $_sType, $_sValue)
    Local $sResult
    RegWrite($_sKeyName, $_sValueName, $_sType, $_sValue)
    Switch @error
        Case 0
            $sResult = "Success"
        Case 1
            $sResult = "Error unable to open requested key"
        Case 2
            $sResult = "Error unable to open requested main key"
        Case 3
            $sResult = "Error unable to remote connect to the registry"
        Case -1
            $sResult = "Error unable to open requested value"
        Case -2
            $sResult = "Error value type not supported"
    EndSwitch
    MsgBox(4096, "Reg Result", $sResult)
EndFunc

 

Link to comment
Share on other sites

Thank you Subz! Your testing helped me a lot. I slightly modified your successful script to add: & @LF & "autocheck autochk *" and it is working well!

#RequireAdmin
Local $sRegRoot = @OSArch = "x64" ? "HKLM64" : "HKLM"
RegWrite($sRegRoot & "\SYSTEM\CurrentControlSet\Control\Session Manager", "BootExecute", "REG_MULTI_SZ", "autocheck autochk /p \??\C:" & @LF & "autocheck autochk *")

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...