Sign in to follow this  
Followers 0
Tripredacus

[Solved] Can't run Sysprep in Windows 8 RP

5 posts in this topic

#1 ·  Posted (edited)

It doesn't seem that I can run Sysprep in Windows 8 RP x64 using @ComSpec. I have no problem running other apps using either Run() or RunWait() in the same app. I am testing in Audit Mode (Administrator account, UAC is disabled). I already searched the forums and didn't find any one else trying to execute Sysprep like this...

This does not work when run compiled:

Run ( @ComSpec & " /c c:\windows\system32\sysprep\sysprep.exe /oobe /shutdown")

Returns error "is not recognized as an internal or external command, operable program or batch file." I don't know how to keep the ComSpec window open, so the only way for me to see this was to hold down the Enter key so I could see the error. Curiously, running this manually works fine:

cmd.exe /c c:\windows\system32\sysprep\sysprep.exe /oobe /shutdown

App is compiled for x86.

OH! Do not try to run this on your workstation!!!

Edited by Tripredacus

Share this post


Link to post
Share on other sites



Compile it for x64 and see if that works, on a 64bit OS the system32 folder isn't always system32 depending upon what program you're trying to run.

BTW, use /k instead of /c to keep the window open.


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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I added MsgBox to show me the @ComSpec value for both an x86 and x64 compiled EXE, but the path is the same. Interestingly enough, the x86 compiled app (using /k) shows me:

'C:\Windows\System32\sysprepsysprep.exe' is not recognized as an internal or external command, operable program or batch file.

However, if I run the x64 app, it actually runs! Unfortunately, I'll have to experiment as I need to get this app to run in 32bit.

Update: Using ShellExecuteWait generates a not found error as well.

Posted Image

I can confirm the path with the run box:

Posted Image

I will run a procmon trace on my test app to see where it is actually looking.

Update2: Even though I am fully qualifying the path to the exe I want to run, Procmon reveals that it is looking for C:Windowssyswow64sysprep.exe...

FWIW, this isn't the first time I've run into this problem of apps looking in the wrong folder for files. Although I can't go into details, another program I was testing uses a DLL. I had it in the same folder as the EXE, but it would only look for it in SysWow64. Since AutoIT was not involved with that particular problem, I imagine this is either a bug or a "feature" in Windows 8.

Edited by Tripredacus

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

In a 64 bit operating system, the system32 folder calls are redirected to the C:WindowsSysWOW64 folder when an x86 program is being run, there's no sysprep.exe in the C:WindowsSysWOW64sysprep folder so the program fails. In the help file is a workaround, quoted below.

Can't quote what I want to quote because the forum is messing up the formatting. In the help file, under Using Autoit, look for the heading "Running under Windows 64-bit Edition" for the work around.

Edited by BrewManNH

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

Share this post


Link to post
Share on other sites

I found this is caused by File System Redirection. When a 32bit application wants to access the System32 folder on a 64bit OS, Windows 8 will default any paths to syswow64 on the idea that a 32bit program would really be looking for the 32bit files. NO!

Anyways, I found a "secret" folder we can use in place of system32 that allows 32bit apps to access the correct folder.

ShellExecuteWait ("c:windowssysnativesysprepsysprep.exe", "/oobe /shutdown")

Answer using the "sysnative" dir instead of "system32":

http://social.technet.microsoft.com/Forums/lt/ITCG/thread/28974b59-1b79-44fd-8bb2-a0a412e18862

Alternatively, for other problems not directly relating to accessing the System32 folder, but still relating to File System Redirection, there are two calls that can be made to disable and then re-enable it.

Wow64DisableWow64FsRedirection function

Posted Image

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning AutoIt community!
      Today, I'm here to ask you if you know how to run an .exe from cmd.exe ( Command Prompt )...
      My intention is to read a .ini file where I store an information that has to be included in the shell, and run an .exe with that information...
      I'll give you an example
      Local $aFileCartellaAuditCopy = _FileListToArray($sPercorsoAuditCopy, "*.txt") If @error Then MsgBox($MB_ICONERROR, "Errore!", "Errore durante la lettura della lista dei file nella directory" & @CRLF & $sPercorsoAuditCopy & @CRLF & "Errore: " & @error) Return False Else Local $iPID = Run("cmd.exe" & ' /k "C:\Users\Portatile-60\Desktop\HmiCheckLogIntegrity.exe" "C:\Users\Portatile-60\Desktop\AuditTrailDosaggio0_20170327_151335_DOSAGGIO_PW_01.txt"') ; & " /k " & '"' & $sHmiCheckLogIntegrity & '"' & " " & '"' & $sPercorsoAuditCopy & "\" & $aFileCartellaAuditCopy[1] & '"', "", @SW_SHOW, $STDOUT_CHILD) Return True EndIf This code is in a function, that returns False if it can retrive at least a file from the path stored in the .ini file...
      Else
      I would like to run the Command Prompt with the .exe and with a parameter of that .exe, but it seems to not work properly.

      Could please anyone tell me why?

      Thanks  
    • WoodGrain
      By WoodGrain
      Hi guys,
      This is probably an obvious one, but I really don't use this command at all so am hoping you can spot my mistake.
      I'm running a powershell script on a schedule with the following script in a function, the function is being called in a loop, but the console process is not closing in the background and I end up with a bunch of console windows running in the background:
      Run(@comspec & ' /k PowerShell.exe -STA -NonInteractive -ExecutionPolicy ByPass -Command "& ''Z:\Powershell\365\GetNextDetails.ps1'' "', "", @SW_HIDE) Thanks!
    • FMS
      By FMS
      Hello,
      I've some troubles whit the run command.
      Below u see 2 command's , 1 is working and the other not. (the first isn't working)
      I think the problem is in te space between program and files.Also I've treid every thing i could think of or the helpfiles handed to me.
      (or maybe I din't find the correct answer:))
      I tried so mush that i don't know anymore if it's the space between program files or not.
      Could somebody point me in the right direction?
      Not working:
      Run(@ComSpec & " /c psexec -i \\127.0.0.1 -u username -p pass -h -d /accepteula C:\Program Files\some_prog\Shell.exe" ,"C:\tools", @SW_HIDE) Working :
      Run(@ComSpec & " /c psexec -i \\127.0.0.1 -u username -p pass /accepteula cmd" , "C:\tools" , @SW_HIDE)  
       
       
       
       
       
       
    • FMS
      By FMS
      hello,
      I'm trying to make a check if a process is running on a remote PC.
      This is what i got this far when I edit a found snippet on this forum.
       
      The function _CMDreturn returns the output of the command line command.
      In this output I want to scan if there is a line whit "process mspaint was not found".
      This I'm trying to do whit StringLeft.
      The problem is that I don't get any error's and also don't get a message if it doesn't exist.
      Could somebody say to me what I'm doing wrong here?
      Or iff there is a better way to do this?
      Thanks in advanced.
       
      #include <Constants.au3> $result= _CMDreturn('C:\Tools\Ps\pslist.exe mspaint') msgbox(0,"Version",$result) Func _CMDreturn($sCommand) $cmdreturn = "" $stream = Run(@ComSpec & " /c " & $sCommand, @SystemDir, @SW_HIDE, $STDOUT_CHILD + $STDIN_CHILD) While 1 $line = StdoutRead($stream) If @error Then ExitLoop If StringLeft($line, 32) = "process mspaint was not found on" Then msgbox(0,"not found",$line) EndIf $cmdreturn &= $line WEnd Return $cmdreturn EndFunc  
    • AutID
      By AutID
      Hello,

      I will put it as simple as possible
      Why this code runs perfectly on 32bit and it fails on 64bit?
      Local $hWND = WinGetProcess("[CLASS:LSS_app]") ConsoleWrite($hWND & @LF) Local $hModuleList = _WinAPI_EnumProcessModules($hWND) If @error Then ConsoleWrite("Error: " & @error & @LF) For $i = 0 To $hModuleList[0][0] - 1 ;~ If StringInStr($hModuleList[$i][1], "sysCap64.dll") Then ConsoleWrite($hModuleList[$i][0] & @LF) ;~ EndIf Next As the title says EnumProcessModules returns error 10 which I have no clue what it is.
      It must be something with autoit or my lack of coding because a similar code in C# will work like a charm on both x86 and x64
      Process[] Processes = Process.GetProcessesByName("winLSS64Cap"); Process nProcess = Processes[0]; Handle = OpenProcess(0x10, true, (uint)nProcess.Id); for(int i = 0; i < nProcess.Modules.Count; i++) { Console.WriteLine(nProcess.Modules[i].ModuleName); }