Hi Everyone,
I'm completely new to VBScript and I need a bit of help. I pieced together a script that opens a command prompt and calls the runas function to execute the Microsoft Office custom maintenance wizard. Can someone take a look at it and tell me if there are any obvious problems? It runs most of the time, but once in a while it has problems and hangs up after the runas command. Any assistance will be greatly appreciated!
Function cmwWizardRun()
Dim oShell, genericPath, cmwDoc, CMWVerifier
Set oShell = CreateObject("Wscript.Shell")
Set WshSysEnv = oShell.Environment("PROCESS")
genericPath = WshSysEnv("USERPROFILE")
cmwDoc = genericPath & "\Local Settings\Temp\Office 11 Maintenance(0000).txt"
CMWVerifier = "C:\Windows\cmwverification.txt"
Dim fso, msg, f1
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(CMWVerifier)) Then
Exit Function
Else
If(fso.FileExists(cmwDoc)) Then
Set f1 = fso.CreateTextFile("c:\Windows\cmwverification.txt", true)
Exit Function
Else
Dim WshShell
Set WshShell = WScript.CreateObject ("WScript.Shell")
WScript.Sleep 1000
WshShell.run "runas /user:mydomain\mmorris"
WScript.Sleep 1000
WshShell.SendKeys "abcdefg"
WshShell.SendKeys "{enter}"
WScript.Sleep 1000
WshShell.SendKeys "\\MYSERVER\cmw\maintwiz.exe /c \\MYSERVER\cmw\exchangeserver.cmw /qb-"
WshShell.SendKeys "{enter}"
WshShell.SendKeys "exit"
WshShell.SendKeys "{ENTER}"
set WshShell = nothing
Set f1 = fso.CreateTextFile("c:\Windows\cmwverification.txt", true)
End If
End If
End Function
Call cmwWizardRun()