Solved

How do I use SUBST command in AutoIT scripting

Posted on 2011-09-02
7
1,438 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
Comment Utility
0
 
LVL 29

Accepted Solution

by:
matrixnz earned 500 total points
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 29

Expert Comment

by:matrixnz
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you for your help!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
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.
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now