[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1526
  • Last Modified:

How do I use SUBST command in AutoIT scripting

I am having trouble getting the SUBST command to work.  I have tried a few varients to see if it works however I can't get the folder to map in AutoIT.  I can run the SUBST command manually and it works fine.  I am on Windows 7.  Anyone have advice or a solution to this?  
#RequireAdmin

$command = "subst f: c:\OfflineCAD"
;Runwait(@ComSpec & " /c " & $command, "")
;Run(@ComSpec & " /c " & $command, "", @SW_HIDE)
ShellExecute(@ComSpec & " /k " & $command, @UserProfileDir, @SW_SHOW)

Open in new window

0
grg-it
Asked:
grg-it
  • 3
  • 3
1 Solution
 
matrixnzCommented:
Have you tried with/without #RequireAdmin

I'm running Windows 7 Professional x64 with UAC switched off, AutoIT Version: 3.3.6.1, ran the following code:

#RequireAdmin
$COMMAND = 'SUBST K: C:\Data'
RunWait(@ComSpec & ' /c ' & $COMMAND, '', @SW_HIDE)

Open in new window


Drive mapped fine for me

Also tried the following without any issues either, both compiled and uncompiled.

#RequireAdmin
$COMMAND = 'SUBST K: C:\Data'
RunWait($COMMAND, '', @SW_HIDE)

Open in new window


0
 
grg-itAuthor Commented:
It works when I remove #requireadmin.  I usually include that in my scripts just in case Windows UAC blocks any script functions.  Any reason the command does not work while #requireadmin is enabled?

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
matrixnzCommented:
Found that it happens intermittently from time to time especially with certain internal commands in AutoIT Scripts.  Especially for commands that don't require an elevated command prompt, there doesn't appear to be any science around it, just trial and error.

Cheers
0
 
grg-itAuthor Commented:
Out of curiosity how would you handle a situation where one function only works without #requireadmin and another function requires it, assuming both functions are need in the same script?
0
 
matrixnzCommented:
It depends, I've actually disabled UAC across our domain, as all staff are Users only and software installs/updates are done via SCCM using local system account which doesn't require #RequireAdmin

In the past, I've actually created separate scripts, so basically one script would include #RequireAdmin another without I then used a third script to wrap the scripts together, fortunately I never had alot of these type of scripts and now with UAC switched off it's not required.  The other method of course is using RunAs command but than I never really like to have user information in the executable.

Hope that made sense.

0
 
grg-itAuthor Commented:
Thank you for your help!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now