zichy Posted March 17, 2006 Posted March 17, 2006 Hi, have a script that gathers information from an ini file that does a runas install of applications listed in ini file. This works fine when an "App" entry is present in ini file. When there is no "App" entry in ini file user is prompted to 'browse' for 'App" and this entry is written to "App" section of ini file. This is implemented and working in script. However im struggling to make the script _restart(), in the example below (on the latest beta) script will keep looping after _restart() without detecting the (newly created through browse) "App" ini file entry (which is created and present in ini file) Anyone able to take a look? Credit to all the code ive used from forum users, appreciated thanks ;;;;;;;;; Code starts Here #include <File.au3> #include <Array.au3> $myUser=IniRead(@ScriptDir & "\runAs.ini","User","Admin","") $myPass=IniRead(@ScriptDir & "\runAs.ini","User","AdminPass","") $myDom=IniRead(@ScriptDir & "\runAs.ini","User","Domain","") $testApps = IniReadSection("runAs.ini", "App") If @error Then $iMsgBoxAnswer = MsgBox(1,"No apps listed in App section of ini file", "Check your ini file's App section for entries to install") Select Case $iMsgBoxAnswer = 1 ;OK _noApp() _restart() Case $iMsgBoxAnswer = 2 ;Cancel Exit EndSelect EndIf _myApp() ;Functions Func _noApp() $myNewApp = FileOpenDialog("Browse for setup file", @DesktopDir, "All (*.*)",1 + 2) $myIni = IniWrite(@ScriptDir & "\runAs.ini","App", "myApp1",$myNewApp) EndFunc Func _myApp() $myApps = IniReadSection("runAs.ini", "App") For $i = 1 To $myApps[0][0] $FileList=_FileListToArray($myApps[$i][0]) RunAsSet ($myUser ,$myDom ,$myPass) RunWait($myApps[$i][1],@TempDir) RunAsSet();<-- To restore initial account Next EndFunc Func _restart() If @Compiled = 1 Then Run( FileGetShortName(@ScriptFullPath)) Else Run( FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath)) EndIf Exit EndFunc ;;;;;;;;;Code ends ;;;Ini file example (runAs.ini) [App] myApp1=c:\windows\notepad.exe [user] Admin=Jack AdminPass=jackPassword Domain=jackDomain ;;end ini example ; Eg if you provide good above user/domain/pass then comment out myApp1 entry you are prompted for browse for application to install then that app is written to ini file and script _restart then its as if the entry isnt being found for 'App' although it exists from 'browsed selection. regards and tio
greenmachine Posted March 17, 2006 Posted March 17, 2006 Do you think it has anything to do with the fact that you're using @ScriptDir & "\runAs.ini" for every other Ini function, but just "runAs.ini" for the IniReadSection function? I would suggest making your ini a variable at the top, like $runAsIni = @ScriptDir & "\runAs.ini", and then using the var $runAsIni for the rest of the ini function calls.
zichy Posted March 17, 2006 Author Posted March 17, 2006 (edited) Thanks greenmachine, thats fixed it Sloppy on my behalf to have missed that, not sure why it affects it but it obviously does, have to have a think about it when i have some time Regards Edited March 17, 2006 by zichy
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