Sign in to follow this  
Followers 0
tedescoj

Sending a dos command as admin

14 posts in this topic

I am having an extremely hard time sending a Net use command to a cmd windows as an administrator. This is so frustrating because it should be so easy to do. here is what I have. The user is not an admin and has absolutely no rights whats so ever. They can not even change the time.

Local $sUserName = "Administrator"

Local $sPassword = "password"

RunAs($sUserName, @ComputerName, $sPassword, 0, @ComSpec & " /c Net use lpt1: \\printserver\Palcom105H4600 /persistent:yes")

it just sits at a admin cmd window and does nothing?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi, tedescoj. Is there any reason you need to use command line? I would suggest looking into the DriveMapAdd function native to AutoIt.

Edit: Disregard, sorry for the hasty post. I just reread your post and see what you're actually trying to do.

The only thing I have seen regarding mapping printers is a resolution that BrewManNH some time ago. It may help lead you down the path you want to go.

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Thanks anyway, but that didn't help. ;)

Share this post


Link to post
Share on other sites

The Net Use command will take the username and password needed to map the printer, try using it with Run instead of RunAs and using the credentials in the Net command.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

But I need to run the command prompt as a admin because the user does not have access to run this command.

Share this post


Link to post
Share on other sites

Then you'd need to run the Net command with credentials that can run it, and passing credentials needed to map the printer, OR you could use the network admin credentials to run the Net command instead of the local administrator. That way, the domain administrator's credentials are being used to run the program and it should use those to map the printer.

BTW, why are you using the LPT1 port for the printer, are you using a lot of DOS only programs?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

yes we are using a in house DOS based program that needs to use this. here is the issue still, I can not run anything as a "Domain Admin" because we don't have those credentials. All we can do is run as a local admin so I need to run cmd.exe as an admin which I can do and then like the old days with autoit send the net use command. But for some reason i can not "send" anything to the cmd window? Why? and how can I do this?

Share this post


Link to post
Share on other sites

Using Send to send characters to the command line is REALLY slow and prone to errors. Just run the command directly. Do you already have an LPT1 on the computer you're trying to use this command on? Because you might be able to get around this by using an unused LPT port number on the computer, LPT2 is rarely used.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

No, this is a network printer. no LPT ports on the computer.

Share this post


Link to post
Share on other sites

I'm aware you're trying to map a network printer, what I was asking is whether you have an LPT1 on the computer currently, not if you have anything connected to it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I am just shocked that this is not possible (and disappointed) with Autoit. i used to turn to Autoit for a lot of things a couple of years ago and now a lot has changed I guess. All i want to do is run the Dos cmd as a admin then execute the net use command as the user. But looks like this is not going to happen ;)

Share this post


Link to post
Share on other sites

I'll ask the question again, is there a physical LPT1 port on the computer that you're running this command on, doesn't matter if anything is plugged into it or not, is there a port in Device Manager that corresponds to LPT1? If there is, read the quote below:

Note In Windows XP, non-administrative users cannot map an LPT port to a network printer path when the LPT port exists on the computer as a physical parallel port.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Yes, it does have a LPT port.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0