Solved

How do I use SUBST command in AutoIT scripting

Posted on 2011-09-02
7
1,481 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
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
Technology Partners: 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!

 
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

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.
A quick guide on how to use Group Policy to create a custom power plan and set it active on Windows 7.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

688 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