sanderson Posted May 4, 2010 Share Posted May 4, 2010 (edited) I am sure this has been asked before but I am unable to find it. I am writing a compiled login script that upgrades some software on a users system. End users cannot see and do not have write access to their own C: drive. The compiled script will check for a file on the system. If that file does not exist then it will run the upgrade with RunAsWait() Administrator credentials. I have tried the following but no file is created at the end of the upgrade to prevent the script running again. The RunAs() parameters work fine on the upgrade installation and the $file handle = 0 when I run the script in the debugger. I'm not sure what to do next so any help is appreciated. chkver = FileOpen($RunPath & "\tamver") If $chkver = -1 Then Exit ;Exit if no Tamver exists EndIf If Int(FileReadLine($chkver,2)) > 1 then $newtam = "c:\tam" & FileReadLine($chkver,2) & ".txt" Else MsgBox(0, "Error", "Error Reading version file. Contact your administrator.") Exit EndIf ; Create touch file to block upgrade again Local $file = RunAs($UserName, $DomainName, $Password, 2, FileOpen($newtam, 10), @SW_HIDE) If $file = -1 Then MsgBox(0, "Error", "Unable to open Tam Upgrade Touch file.") Exit EndIf $myformat = "Upgraded to FileReadLine($chkver,2) on: " & @MON & "/" & @MDAY & "/" & @YEAR & "; " & @HOUR & ":" & @MIN $pid = RunAs($UserName, $DomainName, $Password, 2, FileWriteLine($file, $myformat), "c:\", @SW_HIDE) $pid = RunAs($UserName, $DomainName, $Password, 2, FileClose($file), "c:\", @SW_HIDE) Edited May 4, 2010 by sanderson Link to comment Share on other sites More sharing options...
CaptainCR Posted May 4, 2010 Share Posted May 4, 2010 I'm a complete noob and there is a chance this was just a copy/paste error, but I noticed that you missed the $ sign on the first line of your posted code in front of "chkver"...I am sure this has been asked before but I am unable to find it. I am writing a compiled login script that upgrades some software on a users system. End users cannot see and do not have write access to their own C: drive. The compiled script will check for a file on the system. If that file does not exist then it will run the upgrade with RunAsWait() Administrator credentials. I have tried the following but no file is created at the end of the upgrade to prevent the script running again. The RunAs() parameters work fine on the upgrade installation and the $file handle = 0 when I run the script in the debugger. I'm not sure what to do next so any help is appreciated.chkver = FileOpen($RunPath & "\tamver")If $chkver = -1 Then Exit ;Exit if no Tamver existsEndIfIf Int(FileReadLine($chkver,2)) > 1 then$newtam = "c:\tam" & FileReadLine($chkver,2) & ".txt"Else MsgBox(0, "Error", "Error Reading version file. Contact your administrator.") ExitEndIf; Create touch file to block upgrade again Local $file = RunAs($UserName, $DomainName, $Password, 2, FileOpen($newtam, 10), @SW_HIDE) If $file = -1 Then MsgBox(0, "Error", "Unable to open Tam Upgrade Touch file.") Exit EndIf $myformat = "Upgraded to FileReadLine($chkver,2) on: " & @MON & "/" & @MDAY & "/" & @YEAR & "; " & @HOUR & ":" & @MIN $pid = RunAs($UserName, $DomainName, $Password, 2, FileWriteLine($file, $myformat), "c:\", @SW_HIDE) $pid = RunAs($UserName, $DomainName, $Password, 2, FileClose($file), "c:\", @SW_HIDE) Link to comment Share on other sites More sharing options...
99ojo Posted May 4, 2010 Share Posted May 4, 2010 (edited) Hi, welcome to forum. Please use the autoit tags for your code. You can't run an AutoIT integrated function as admin in this way. $pid = RunAs($UserName, $DomainName, $Password, 2, FileWriteLine($file, $myformat), "c:\", @SW_HIDE) If yes, someone should correct me. You might try: $chkver = FileOpen($RunPath & "\tamver") If $chkver = -1 Then Exit ;Exit if no Tamver exists EndIf If Int(FileReadLine($chkver,2)) > 1 then $newtam = "c:\tam" & FileReadLine($chkver,2) & ".txt" Else MsgBox(0, "Error", "Error Reading version file. Contact your administrator.") Exit EndIf FileClose ($chkver) ; Create touch file to block upgrade again ;Local $file = RunAs($UserName, $DomainName, $Password, 2, FileOpen($newtam, 10), @SW_HIDE) ;If $file = -1 Then ;MsgBox(0, "Error", "Unable to open Tam Upgrade Touch file.") ;Exit ;EndIf $myformat = "Upgraded to FileReadLine($chkver,2) on: " & @MON & "/" & @MDAY & "/" & @YEAR & "; " & @HOUR & ":" & @MIN $pid = RunAsWait ($UserName, $DomainName, $Password, 2, @ComSpec & " /c echo " & $myformat & ">>" & $newtam, "c:\", @SW_HIDE) If @error Then MsgBox(0, "Error", "Unable to open Tam Upgrade Touch file.") ;-)) Stefan Edited May 4, 2010 by 99ojo Link to comment Share on other sites More sharing options...
sanderson Posted May 4, 2010 Author Share Posted May 4, 2010 Thanks for the help. Yes it was a copy paste error on the $chkver and your solution worked well 99ojo. Thank you. I also had to change the logon_flag to 0 to allow the file write. Not really sure why but it works so all is well. thank you for the replies.. 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