PCrane Posted March 13, 2008 Share Posted March 13, 2008 I am new to this scripting. I am wanting to create a script to basically go in a delete a certain file on the machine and than stop a service from running. Force a gpupdate policy refresh, than start the service back up and delete the script off the machine. Right now the command prompt shows and i do not want that to show. Want it more like a service that runs in the background. Maybe with a progress bar, like please wait or something of that nature. Also need to tweak the first msg box some. Seems when you press cancel or the x the script deletes itself. Also and needing this script to run as the local admin on the machine. Any help would be much appreciated. Here is the code i am working with: expandcollapse popup$g_szVersion = "Software reporting fix SD" If WinExists($g_szVersion) Then Exit; It's already running AutoItWinSetTitle($g_szVersion) ; Rest of your script goes here ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Question If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(305,"Warning!","Close all open applications before proceeding") Select Case $iMsgBoxAnswer = 1;OK Case $iMsgBoxAnswer = 2;Cancel EndSelect If $iMsgBoxAnswer = 2 Then Exit RunAsSet("admin",@ComputerName, "password") Run("C:\WINDOWS\system32\cmd.exe") Send(" cd\") Send("{ENTER}") Send("cd program files") Send("{ENTER}") Send("cd ca") Send("{ENTER}") Send("cd unicenter dsm") Send("{ENTER}") Send("cd agent") Send("{ENTER}") Send("cd units") Send("{ENTER}") Send("cd 00000001") Send("{ENTER}") Send("cd uam") Send("{ENTER}") Send("cd bak") Send("{ENTER}") Send("del amsoft.xml") Send("{ENTER}") Send("caf stop") Send("{ENTER}") Sleep("9000") Send("gpupdate /force") Send("{ENTER}") Sleep("22000") Send("caf start") Send("{ENTER}") Sleep("20000") Send("exit") Send("{ENTER}") Func OnAutoItExit() _SelfDelete() EndFunc Func _SelfDelete() Local $sCmdFile FileDelete(@TempDir & "Scratch.bat") $sCmdFile = ':loop' & @CRLF _ & 'del "' & @ScriptFullPath & '"' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & 'del ' & @TempDir & 'Scratch.bat' FileWrite(@TempDir & "Scratch.bat", $sCmdFile) Run(@TempDir & "Scratch.bat", @TempDir, @SW_HIDE) EndFunc; SelfDelete Link to comment Share on other sites More sharing options...
spudw2k Posted March 13, 2008 Share Posted March 13, 2008 $path = "C:\Program Files\ca\unicenter dsm\agent\units\00000001\uam\bak\" $file = "amsoft.xml" If FileExists($path & $file) Then FileDelete($path & $file) RunWait(@Comspec & " /c " $path & "caf stop") RunWait(@Comspec & " /c " & "gpudate /force") RunWait(@Comspec & " /c " $path & "caf start") Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
PCrane Posted March 13, 2008 Author Share Posted March 13, 2008 Thanks. I removed most of the command line codes. But after trying to run the script, it gave a Line -1: Error:Error in expression ? This needs to run with local admin rights as well. How would i code that based off the original code i had? Link to comment Share on other sites More sharing options...
spudw2k Posted March 13, 2008 Share Posted March 13, 2008 (edited) Thanks. I removed most of the command line codes. But after trying to run the script, it gave a Line -1: Error:Error in expression ? This needs to run with local admin rights as well. How would i code that based off the original code i had? The code you had above for the admin set should work. The code I made should replace Run("C:\WINDOWS\system32\cmd.exe")Send(" cd\")Send("{ENTER}")Send("cd program files")Send("{ENTER}")Send("cd ca")Send("{ENTER}")Send("cd unicenter dsm")Send("{ENTER}")Send("cd agent")Send("{ENTER}")Send("cd units")Send("{ENTER}")Send("cd 00000001")Send("{ENTER}")Send("cd uam")Send("{ENTER}")Send("cd bak")Send("{ENTER}")Send("del amsoft.xml")Send("{ENTER}")Send("caf stop")Send("{ENTER}")Sleep("9000")Send("gpupdate /force")Send("{ENTER}")Sleep("22000")Send("caf start")Send("{ENTER}")Sleep("20000")Send("exit")Send("{ENTER}")Repost the whole code and I'll check it out. Edited March 13, 2008 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
PCrane Posted March 13, 2008 Author Share Posted March 13, 2008 expandcollapse popup$g_szVersion = "Software reporting fix SD" If WinExists($g_szVersion) Then Exit; It's already running AutoItWinSetTitle($g_szVersion) ; Rest of your script goes here ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Question If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(305,"Warning!","Close all open applications before proceeding") Select Case $iMsgBoxAnswer = 1;OK Case $iMsgBoxAnswer = 2;Cancel EndSelect If $iMsgBoxAnswer = 2 Then Exit RunAsSet("username",@ComputerName, "password") Run("C:\WINDOWS\system32\cmd.exe") $path = "C:\Program Files\ca\unicenter dsm\agent\units\00000001\uam\bak\" $file = "amsoft.xml" If FileExists($path & $file) Then FileDelete($path & $file) RunWait(@Comspec & " /c " $path & "caf stop") RunWait(@Comspec & " /c " & "gpudate /force") RunWait(@Comspec & " /c " $path & "caf start") Func OnAutoItExit() _SelfDelete() EndFunc Func _SelfDelete() Local $sCmdFile FileDelete(@TempDir & "Scratch.bat") $sCmdFile = ':loop' & @CRLF _ & 'del "' & @ScriptFullPath & '"' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & 'del ' & @TempDir & 'Scratch.bat' FileWrite(@TempDir & "Scratch.bat", $sCmdFile) Run(@TempDir & "Scratch.bat", @TempDir, @SW_HIDE) EndFunc; SelfDeleteThis gives me error:Line -1:Error:Error in expression Link to comment Share on other sites More sharing options...
spudw2k Posted March 13, 2008 Share Posted March 13, 2008 (edited) My bad. Typo on my part. Needed and additional & between " /c " and $path I also removed the Run("C:\Windows\system32\cmd.exe") line. Not neccessary anymore. Don't forget to change user and pass expandcollapse popup$g_szVersion = "Software reporting fix SD" If WinExists($g_szVersion) Then Exit; It's already running AutoItWinSetTitle($g_szVersion) ; Rest of your script goes here ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Question If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(305,"Warning!","Close all open applications before proceeding") Select Case $iMsgBoxAnswer = 1;OK Case $iMsgBoxAnswer = 2;Cancel EndSelect If $iMsgBoxAnswer = 2 Then Exit RunAsSet("username",@ComputerName, "password") $path = "C:\Program Files\ca\unicenter dsm\agent\units\00000001\uam\bak\" $file = "amsoft.xml" If FileExists($path & $file) Then FileDelete($path & $file) RunWait(@Comspec & " /c " & $path & "caf stop") RunWait(@Comspec & " /c " & "gpudate /force") RunWait(@Comspec & " /c " & $path & "caf start") Func OnAutoItExit() _SelfDelete() EndFunc Func _SelfDelete() Local $sCmdFile FileDelete(@TempDir & "Scratch.bat") $sCmdFile = ':loop' & @CRLF _ & 'del "' & @ScriptFullPath & '"' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & 'del ' & @TempDir & 'Scratch.bat' FileWrite(@TempDir & "Scratch.bat", $sCmdFile) Run(@TempDir & "Scratch.bat", @TempDir, @SW_HIDE) EndFunc; SelfDelete Edited March 13, 2008 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
PCrane Posted March 13, 2008 Author Share Posted March 13, 2008 Ok it was able to delete the needed file, but the service did not seem to stop at all? Link to comment Share on other sites More sharing options...
spudw2k Posted March 13, 2008 Share Posted March 13, 2008 (edited) Ok, is caf an executbale in the same dir as the xml file? That's what I assumed from the code cause I've never heard of a prog called caf. Try changing the first and second RunWait line to this. RunWait(@Comspec & " /c " & "caf stop") or better RunWait(@Comspec & " /c " & chr(34) & "fullpath to caf file\caf" & chr(34) & " stop") Edited March 13, 2008 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
PCrane Posted March 13, 2008 Author Share Posted March 13, 2008 Awesome that seemed to work. The only thing i noticed, is when you either click cancel or the X the file will delete itself? Link to comment Share on other sites More sharing options...
spudw2k Posted March 13, 2008 Share Posted March 13, 2008 (edited) I think that is the nature of the _SelfDelete function. If you want it to delete itself only if the script completes, then pull the _SelfDelete call out of the OnAutoItExit() func. $g_szVersion = "Software reporting fix SD" If WinExists($g_szVersion) Then Exit; It's already running AutoItWinSetTitle($g_szVersion) ; Rest of your script goes here ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Question If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(305,"Warning!","Close all open applications before proceeding") Select Case $iMsgBoxAnswer = 1;OK Case $iMsgBoxAnswer = 2;Cancel EndSelect If $iMsgBoxAnswer <> 1 Then Exit RunAsSet("username",@ComputerName, "password") $path = "C:\Program Files\ca\unicenter dsm\agent\units\00000001\uam\bak\" $file = "amsoft.xml" If FileExists($path & $file) Then FileDelete($path & $file) RunWait(@Comspec & " /c " & "caf stop") RunWait(@Comspec & " /c " & "gpudate /force") RunWait(@Comspec & " /c " & "caf start") _SelfDelete() Func _SelfDelete() Local $sCmdFile FileDelete(@TempDir & "Scratch.bat") $sCmdFile = ':loop' & @CRLF _ & 'del "' & @ScriptFullPath & '"' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & 'del ' & @TempDir & 'Scratch.bat' FileWrite(@TempDir & "Scratch.bat", $sCmdFile) Run(@TempDir & "Scratch.bat", @TempDir, @SW_HIDE) EndFunc; SelfDelete Edited March 13, 2008 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now