Sign in to follow this  
Followers 0
JustMeAgain

DirCreate not creating a folder

4 posts in this topic

Specs:

AutoIt ver: 3.1.1.0

OS: Windows XP SP2

What I'm trying to do:

A normal Windows users will run the following compiled script and I use RunAsSet() to elevate their privligies to local admin to create a folder under @ProgramFilesDir. This will copy just the needed UltraVNC files for VNC server or VNC viewer (I have an installer for each and they both have the same problem) to the sub folder under @ProgramFilesDir. Then the user with the VNC server can create an encrypted tunel using reverse VNC. (I've written, but not really tested yet, a launcher for VNC server and VNC viewer in listen mode.)

What problem is occuring: :o

DirCreate will not create $path (@ProgramFilesDir & "\UltraVNC"). MsgBox(0, "", $path) shows the correct path (C:\Program Files\UltraVNC). I've added "RunWait(@ComSpec & " /k c:\util\whoami.exe")" right after the RunAsSet command, which shows "Administrator" (whoami.exe is a little DOS app that gives you the logged on user). I can use that same command prompt to create my sub folder under C:\program files. So I know this account has the rights to create the folder. My script, compiled and executed from the C: drive, errors out with my msgbox about being unable to create the folder.

My question:

Does anyone have any ideas on why this is failing? I'm sure it's probably a problem with my script and I'm too tired to see what's wrong. Searching the forums showed a lot of people using DirCreate, but I didn't see where people were having this problem.

UltraVNC Server Install Code:

Dim $version = "1.0.0"

Call("main")

Func main()
   
   Local $instPath = @ProgramFilesDir & "\UltraVNC"  ;Folder for file extraction.
   Local $admin = "Administrator"
   Local $passwd = "******"

   $prompt = MsgBox(36, @ScriptName & " Version " & $version, _
   "This will install the standalone UltraVNC server on your computer." & @CRLF & _
   "Do you want to continue?")
   If $prompt = "7" Then Call("end")
   
   install($instPath, $admin, $passwd)    ;Extract the embedded files.
   
   MsgBox(64, "Exiting " & @ScriptName & " Version " & $version, "Finished installing.")
   Call("end")                                ;Exit.
EndFunc


Func install($path, $adm, $pwd)
;Extract the embedded files.  See the comments at the top for more information.
;$path = $instPath = Folder to extract (i.e. install) the files.
;$adm = $admin = User account with elevated privileges.
;$pwd = $passwd = User password to use with $adm.

   Local $winvnc = "winvnc.exe"
   Local $winvncicon = "winvnc.ico"
   Local $rc4 = "rc4.key"
   Local $MSRC4Plugin = "MSRC4Plugin_NoReg.dsm"
   Local $launchwinvnc = "LaunchWinVNC.exe"

   TrayTip(@ScriptName, "Installing files.", 30, 1)
   RunAsSet($adm, @ComputerName, $pwd)
   If FileExists($path) = "0" Then
      If DirCreate($path) = "0" Then
         MsgBox(4112, "ERROR: Unable to create folder", "Unable to create the following folder:" & @CRLF & _
         "   " & $path & @CRLF & _
         "Create the folder manually and then run " & @ScriptName & " again." & @CRLF & _
         "Click OK to exit.")
         Call("end")
      EndIf
   EndIf
   If FileInstall("winvnc.exe", $path & "\" & $winvnc, 1) = "0" Then
      MsgBox(16, "ERROR: Unable to extract file", "Unable to extract " & $winvnc & " to the destination directory." & @CRLF & _
      "Exiting without finishing the install.")
      Call("end")
   EndIf
   If FileInstall("winvnc.ico", $path & "\" & $winvncicon, 1) = "0" Then
      MsgBox(16, "ERROR: Unable to extract file", "Unable to extract " & $winvncicon & " to the destination directory." & @CRLF & _
      "Exiting without finishing the install.")
      Call("end")
   EndIf
   If FileInstall("rc4.key", $path & "\" & $rc4, 1) = "0" Then
      MsgBox(16, "ERROR: Unable to extract file", "Unable to extract " & $rc4 & " to the destination directory." & @CRLF & _
      "Exiting without finishing the install.")
      Call("end")
   EndIf
   If FileInstall("MSRC4Plugin_NoReg.dsm", $path & "\" & $MSRC4Plugin, 1) = "0" Then
      MsgBox(16, "ERROR: Unable to extract file", "Unable to extract " & $MSRC4Plugin & " to the destination directory." & @CRLF & _
      "Exiting without finishing the install.")
      Call("end")
   EndIf
   If FileInstall("LaunchWinVNC.exe", $path & "\" & $launchwinvnc, 1) = "0" Then
      MsgBox(16, "ERROR: Unable to extract file", "Unable to extract " & $launchwinvnc & " to the destination directory." & @CRLF & _
      "Exiting without finishing the install.")
      Call("end")
   EndIf
   TrayTip(@ScriptName, "Creating the Desktop shortcut.", 30, 1)
   FileCreateShortcut($path & "\" & $launchwinvnc, @DesktopCommonDir & "\Launch UltraVNC Server.lnk", $path, "", "Launch UltraVNC server", $path & "\" & $winvncicon)
   RunAsSet()
   TrayTip("", "", 0)

   Return
EndFunc


Func end()
   Exit
EndFunc

Thanks for any help you can provide.

Share this post


Link to post
Share on other sites



RunAsSet() ONLY changes the credentials of the programs run with RUN() or RUNWAIT()... NOT the other commands.

A simple way arround this is to rerun the script after RunAsSet().....

AutoItSetOption("RunErrorsFatal", 0) 
AutoItSetOption("TrayIconHide", 1) 
Break(0)
$USERNAME = "Administrator"
$PASSWORD = "Secret"
$RUN = 0      ; run indicator 
; retrieve the cycle from commandline
If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]
If $RUN = 0 Then
   RunAsSet($USERNAME, @ComputerName, $PASSWORD)
   Run('"' & @ScriptFullPath & '" " 1"') 
   If @error Then MsgBox(4096+32,"Error", "Error starting under admin mode")
   Exit
EndIf
; commands go here that require Administrator rights

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

RunAsSet() ONLY changes the credentials of the programs run with RUN() or RUNWAIT()... NOT the other commands.

A simple way arround this is to rerun the script after RunAsSet().....

AutoItSetOption("RunErrorsFatal", 0) 
AutoItSetOption("TrayIconHide", 1) 
Break(0)
$USERNAME = "Administrator"
$PASSWORD = "Secret"
$RUN = 0     ; run indicator 
; retrieve the cycle from commandline
If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]
If $RUN = 0 Then
   RunAsSet($USERNAME, @ComputerName, $PASSWORD)
   Run('"' & @ScriptFullPath & '" " 1"') 
   If @error Then MsgBox(4096+32,"Error", "Error starting under admin mode")
   Exit
EndIf
; commands go here that require Administrator rights
Thanks, JdeB! :o Very cool code.

I looked back at the help for RunAsSet and sure enough, it states "(t)his function allows subsequent Run and RunWait functions to run as a different user...". DOH! I've successfully used RunAsSet with previous scripts. I guess I always just used it with Run and RunWait commands.

Now that I've been educated, this would be another option, but perhaps not as clean as a script that calls itself.

FileInstall("adminCmds.exe", @TempDir & "\adminCmds.exe") ; adminCmds.exe = commands to run as the administrator.
RunAsSet($USERNAME, @ComputerName, $PASSWORD)
RunWait(@TempDir & "\adminCmds.exe")
RunAsSet()

Share this post


Link to post
Share on other sites

Thanks, JdeB! :geek: Very cool code.

I looked back at the help for RunAsSet and sure enough, it states "(t)his function allows subsequent Run and RunWait functions to run as a different user...". DOH! I've successfully used RunAsSet with previous scripts. I guess I always just used it with Run and RunWait commands.

Now that I've been educated, this would be another option, but perhaps not as clean as a script that calls itself.

FileInstall("adminCmds.exe", @TempDir & "\adminCmds.exe"); adminCmds.exe = commands to run as the administrator.
RunAsSet($USERNAME, @ComputerName, $PASSWORD)
RunWait(@TempDir & "\adminCmds.exe")
RunAsSet()
Yes you can FileInstall() another file, but increases the size by 2 when it is a script.... but works fine too ... :o

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0