Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Deploying App Using Winbatch 'Wrapper' Via Web
Then the first exe runs the second exe with a special parameter telling it that it is the second exe (or the exe can check its localtion and if the local hard dirive...)
Then the second exe can run itself again (th third time) with RunWithLogon to gain access to admin privileges.
Here's some sample code:
; This script (when debugged) should do the following
; 1) If on a network drive, copy itself to a local drive then run the local copy
; 2) If run from a local drive, use RunWithLogon run itself to grant admin privileges
; Must run in Win2000 or newer
; It does need to know the Admin account and password and optionall domain
; Change the following to suite your system
runas_user = "Administrator"
runas_pswd = "password"
runas_domain = ComputernameGet(0);Use local account
; Step 1, determine current situation
runstate=0 ; 0 means don;t know
; ; 1 means running as an Admin
; ; 2 means running on local drive, but not admin
; ; 3 means running on network drive
;Get entire parameter line for examination
moiparams=IntControl(1006,0,0,0,0)
If StrIndexNC(moiparams,"URADMIN",0,@FWDSCAN)
; Already launched as admin
param0 = param0 -1 ; Remove the URADMIN param from further consideration
runstate=1 ; already running as admin
Else
; Get current exe name
moi=WinExename("")
If moi=="\\""
;UNC network drive
runstate=3 ; network drive
Else
;see if network drive letter
moidrive=StrSub(moi,1,1)
;get local drive list uppercase also
networkdrives=DiskScan(4)
;See if is drive letter is on network drive list
If StrIndex(networkdrives,moidrive,0,@FWDSCAN) != 0
;drive letter found in network drive list
runstate=3 ; running on network drive
Else
runstate=2 ; running on local machine but not an admin
EndIf
EndIf
EndIf
Terminate(runstate==0,"Error","Script confused about current runstate")
; Step 2 now that run state is known, do something about it
Switch runstate
Case 1 ; running as admin
; break out of switch statement and do Admin code below
Break
Case 2 ; running on local drive. Need admin privileges
If WinVersion(5) >= "2-5-0" ;Win2000 or newer
;NOTE: For security reasons *always* assign the password
; to a variable and then use the variable in the RunWithLogon
; statement. NEVER hardcode the password into the
; RunWithLogon statement or else the password my be
; exposed if the RunWithLogon fails on some kind of error
; This is also a good idea with the userid and domain
; information
moi=WinExename("")
moiparams=StrCat(moiparams, " URADMIN")
; The following should be on one line
RunWithLogon(moi, moiparams, "", @NORMAL, @NOWAIT,runas_user, runas_domain, runas_pswd,0)
Exit
Else
Message("Platform error","Script is not designed for this OS.")
Exit
EndIf
Break
Case 3 ; running from network drive. Make local copy
tempfile=FileCreateTemp("~ex")
FileDelete(tempfile)
;make a new directory
temppath=StrCat(FilePath(tempfile),"WBINST\")
If DirExist(temppath)==@FALSE Then DirMake(temppath)
DestEXE=StrCat(temppath,"WBINST.xex") ; using xex extension to stop user from clicking on it
moi=WinExename("")
FileCopy(moi,DestEXE,0)
;Message(DestExe,moiparams)
Run(DestExe,moiparams)
Exit
Break
EndSwitch
Terminate(runstate!=1,"Error","Script should be in admin mode now")
;-------------------------------
; Running in Admin mode now.
;-------------------------------
Message("Do stuff","here")
Exit
Article ID: W15278
File Created: 2009:03:25:13:57:54
Last Updated: 2009:03:25:13:57:54