Jump to content

Script Not Un-Pausing


Recommended Posts

Hello First let me say thank you for any help you can provide. This script installs powershell and all its dependencies. The problem i am having is that i think RunWait isnt working correctly or it is and i wrote it wrong.  The Script is  not un pausing itself.  Can anyone let me know what i am doing wrong here? Should i even be using that command?

$osv = @OSVersion
$ost = @OSArch

Local $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine\", "PowerShellVersion")
Local $var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5\","Version")


Switch @OSVersion
        Case "WIN_2008"

         If @OSArch = "x86" Then

               If $var <> "1.0" Then

                    $CMD = "C:\Temp\dotNetFramework\dotnetfx35setup.exe /q /norestart"
                       RunWait(@comspec & " /k " & $CMD)
                    Sleep (60000)

                    $CMD = "C:\Temp\BITS\x86.msu  /quiet /norestart"
                       RunWait(@comspec & " /c " & $CMD)
                    Sleep (60000)

                    $CMD = "C:\Temp\WMF\x86.msu  /quiet /norestart"
                       RunWait(@comspec & " /c " & $CMD)

MsgBox(0, "", "Done")


               Else

                    $CMD = "ServerManagerCmd.exe -remove PowerShell -restart"
                        RunWait(@comspec & " /k " & $CMD)
                    Sleep (60000)

                    $CMD = "C:\Temp\dotNetFramework\dotnetfx35setup.exe /q /norestart"
                       RunWait(@comspec & " /k " & $CMD)
                    Sleep (60000)

                    $CMD = "C:\Temp\BITS\x86.msu  /quiet /norestart"
                       RunWait(@comspec & " /c " & $CMD)
                    Sleep (60000)

                    $CMD = "C:\Temp\WMF\x86.msu  /quiet /norestart"
                       RunWait(@comspec & " /c " & $CMD)

MsgBox(0, "", "Done")


               EndIf

         ElseIf @OSArch = "x64" Then


           MsgBox(0, "", "64 Bit Win 2008")

               If $var <> "1.0" Then

                    $CMD = "C:\Temp\dotNetFramework\dotnetfx35setup.exe /q /norestart"
                       RunWait(@comspec & " /k " & $CMD)
                    Sleep (60000)

                    $CMD = "C:\Temp\BITS\x64.msu  /quiet /norestart"
                       RunWait(@comspec & " /c " & $CMD)
                    Sleep (60000)

                    $CMD = "C:\Temp\WMF\x64.msu  /quiet /norestart"
                       RunWait(@comspec & " /c " & $CMD)

MsgBox(0, "", "Done")

               Else

                    $CMD = "ServerManagerCmd.exe -remove PowerShell -restart"
                       RunWait(@comspec & " /k " & $CMD)
                   Sleep (60000)

                        $CMD = "C:\Temp\dotNetFramework\dotnetfx35setup.exe /q /norestart"
                       RunWait(@comspec & " /k " & $CMD)
                    Sleep (60000)

                    $CMD = "C:\Temp\BITS\x64.msu  /quiet /norestart"
                       RunWait(@comspec & " /c " & $CMD)
                    Sleep (60000)

                    $CMD = "C:\Temp\WMF\x64.msu  /quiet /norestart"
                       RunWait(@comspec & " /c " & $CMD)

MsgBox(0, "", "Done")


               EndIf
         EndIf



 Case "WIN_2003","WIN2003R2"

         If @OSArch = "x86" Then



               If $var <> "1.0" Then

                    $CMD = "C:\Temp\dotNetFramework\dotnetfx35setup.exe /q /norestart"
                       RunWait(@comspec & " /k " & $CMD)
                    Sleep (120000)

                    $CMD = "C:\Temp\WMF\x86.exe  /quiet /norestart"
                       RunWait(@comspec & " /c " & $CMD)





               Else


                    Sleep (360000)

                    $CMD = "C:\Temp\dotNetFramework\dotnetfx35setup.exe /q /norestart"
                       RunWait(@comspec & " /k " & $CMD)
                    Sleep (360000)

                    $CMD = "C:\Temp\WMF\x86.exe  /quiet /norestart"
                       RunWait(@comspec & " /c " & $CMD)





               EndIf

         ElseIf @OSArch = "x64" Then




               If $var <> "1.0" Then

                     $CMD = "C:\Temp\dotNetFramework\dotnetfx35setup.exe /q /norestart"
                       RunWait(@comspec & " /k " & $CMD)
                    Sleep (120000)

                    $CMD = "C:\Temp\WMF\x64.exe  /quiet /norestart"
                       RunWait(@comspec & " /c " & $CMD)

               Else


                  Sleep (360000)

                     $CMD = "C:\Temp\dotNetFramework\dotnetfx35setup.exe /q /norestart"
                       RunWait(@comspec & " /k " & $CMD)

                  Sleep (120000)

                     $CMD = "C:\Temp\WMF\x86.exe  /quiet /norestart"
                       RunWait(@comspec & " /c " & $CMD)


               EndIf


         EndIf



  Case Else

   MsgBox(0, "", "Not a Supported OS Version")

EndSwitch
Link to comment
Share on other sites

I would insert MsgBoxs where you think it could be pausing, to see if it is truly pausing in those areas.

Almost like a path, saying I'm here, now I'm here. Helps the debug process. :)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Hello!

Sorry I think you are better in this then me, but I may help with some stupid questions :)

A. I can't see where CMD is decleared as a variable. 

B. is @comspec & "  /c " & "C:TempWMFx86.exe ... for example a valid CMD line order?

C. you could make the 

$CMD = "C:\Temp\dotNetFramework\dotnetfx35setup.exe /q /norestart"

                       RunWait(@comspec & " /k " & $CMD)

                    Sleep (60000)

 

                    $CMD = "C:\Temp\BITS\x64.msu  /quiet /norestart"

                       RunWait(@comspec & " /c " & $CMD)

                    Sleep (60000)

 

                    $CMD = "C:\Temp\WMF\x64.msu  /quiet /norestart"

                       RunWait(@comspec & " /c " & $CMD)

and

$CMD = "C:\Temp\dotNetFramework\dotnetfx35setup.exe /q /norestart"

                       RunWait(@comspec & " /k " & $CMD)

 

                  Sleep (120000)

 

                     $CMD = "C:\Temp\WMF\x86.exe  /quiet /norestart"

                       RunWait(@comspec & " /c " & $CMD)

in to separete functions, simplyfiyinf the code maybe.

If you wanted to use RunWait why are the sleeps that long?

Edit: again you are much likely better in this then me :)

Edited by SorryButImaNewbie
Link to comment
Share on other sites

A. Unless Opt of MustDelcareVars was on, wouldn't matter.

B. It looks fine to me.

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

@MikahS    Thanks for replying. That is what i did  It will install the uninstall ps1 and then it pauses. I put yo sucka first command and that is as far as it goes.  So i know that is is stopping right after when the RunWait Command starts.

@SorryButImaNewbie.    I am not very good either.  I thought it was a valid.  I looked here to verify:  "https://www.autoitscript.com/autoit3/docs/functions/RunWait.htm" I could be reading it wrong though. Well I know it is quite long maybe there is a better way.  My thinking is this. I will be deploying this scripts and different versions of windows and a alot of checks needs to take place. So i wrote it like that to make those checks. I am not sure if that makes sense or if that even answers your question. Thank you for your feed back. I am going to look at that order again to make sure i am doing it right.

Link to comment
Share on other sites

This could be due to a process that doesn't stop, RunWait waits for the program to terminate, so if it never terminates it will always be running.

Not sure if this is your case, but maybe trying it with using the Run function, and finding the process and use ProcessWaitClose to check it?

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Your code can be simplified and shortened a lot by having those commands run in a function, like Sorry suggested. It will save you a lot of typing too, and if you want to (for instance) change the RunWait to Run or something, you'll only have to change that in one place instead of doing error prone search/replace or tedious manual labor.

Also, like Sorry said, your waiting periods are very long, sleep(360000) means pausing the script for 6 full minutes. And that is after the RunWait has already paused the script waiting for the command to finish.

Third, you are mixing /k and /c in running @ComSpec. The /k switch runs the commandline and executes the command, but normally leaves the commandline open after the command is done, waiting for you to actually close the commandline, and RunWait in turn pauses the script waiting for the @ComSpec to end. Don't know if that /k was intentional, thought I'd mention it.

Lastly, if you're going to read the registry and do system thingies like that, you may need the #RequireAdmin on top of your script (requests elevation to do admin tasks).

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

I believe the /k switch keeps the window open.

/K  Carries out the command specified by string but remains

As J1 suggests, don't use /k. ;)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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...