Solved

How do I use SUBST command in AutoIT scripting

Posted on 2011-09-02
7
1,446 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 74
Best Way to Clone 256GB SSD Boot Drive to New 512GB SSD in Windows 7 PC 17 81
Beginner to Unreal Engine 4 5 57
Turn on intranet settings 1 36
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.
While working, an annoying popup showing below will come and we cannot cancel or close it form the screen. The error message will come again and again.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

932 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now