Solved

How do I use SUBST command in AutoIT scripting

Posted on 2011-09-02
7
1,452 Views
Last Modified: 2012-06-21
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
Comment
Question by:grg-it
  • 3
  • 3
7 Comments
 
LVL 8

Expert Comment

by:Chetan Khurana
ID: 36475951
0
 
LVL 29

Accepted Solution

by:
matrixnz earned 500 total points
ID: 36477473
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
 
LVL 1

Author Comment

by:grg-it
ID: 36490995
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 29

Expert Comment

by:matrixnz
ID: 36491742
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
 
LVL 1

Author Comment

by:grg-it
ID: 36491788
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
 
LVL 29

Expert Comment

by:matrixnz
ID: 36491972
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
 
LVL 1

Author Comment

by:grg-it
ID: 36498631
Thank you for your help!
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Change the background and font colors in Notepad++ 5 86
Unknown Windows 7 64-bit Screen Appearance 5 38
Math Equation 23 87
Hyper V on Windows 7 and DISK2VHD Question 3 68
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question