Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I want to run a command in CMD (Command Prompt)

Status
Not open for further replies.

Crash171

Programmer
Sep 5, 2014
30
US
As the title states, I would like to have a simple macro to run a command in CMD. To expand on this a little, I want to enter a "net use" command.

To open CMD, this works:

Code:
Shell "C:\Windows\System32\cmd.exe"

Now how do I send the command? The command is basically "net use j: \\devicename /user:username password".


I would love any input!! Also if there is a better way to open CMD then using "Shell", please let me know.
 
Still working on this one with no progress... But I can't give up.
 
Tried this:

Code:
Shell "C:\Windows\System32\cmd.exe"
filenameout$ = "C:\Windows\System32\cmd.exe"
        Sess0.Screen.MoveTo 24,28
        Sess0.Screen.Sendkeys("net use j: \\devicename ")
        ODR1$ = Sess0.Screen.GetString(24,28,38)
        Print #1,ODR1$

It opens the command prompt, but does not enter anything into it. My thinking was I could copy the text from Attachmate into the command prompt by designating it as "ODR1$". I use this method to copy order numbers into a text document, but it didn't work.
 
I'm not sure what I was thinking with the "Shell". Anyway, below is today's progress. Now I have two questions....[highlight #FCAF3E]What object type do I need to use??[/highlight] [highlight #73D216]Will "bWaitOnReturn = True" work to let CMD process the like before moving onto the next?[/highlight] [highlight #3465A4]Will this section correctly close and end CMD?[/highlight]


Code:
'Declare the CMD as Object
        Dim xCMD As Object
        [highlight #FCAF3E]Set xCMD = CreateObject("something.something")[/highlight]
        xCMD.Open FileName:="C:\Windows\System32\cmd.exe"
        xCMD.Visible = True
        [highlight #73D216]bWaitOnReturn = True[/highlight]
        
        
'Start work
        xCMD.Sendkeys("net use j: \\devicename")
        
'--------------------------------------------------------------------------------
'   Enter your Username Below
'--------------------------------------------------------------------------------

        xCMD.Sendkeys("/USER:USERNAME")


'--------------------------------------------------------------------------------
'   Enter your Username Above
'--------------------------------------------------------------------------------
'   Enter your Password Below
'--------------------------------------------------------------------------------
        
        xCMD.Sendkeys("PASSWORD")

'--------------------------------------------------------------------------------
'   Enter your Password Above
'--------------------------------------------------------------------------------

[highlight #3465A4]xCMD.quit
Set xCMD = nothing[/highlight]

	System.TimeoutValue = OldSystemTimeout
End Sub
 
please excuse me for asking, but exactly what are you trying to accomplish?
 
I don't mind you asked at all. I figured it out last night. My goal was to gain access to a virtual drive using a Net Use command in CMD. We have to access the drive once a day. So now I have created the below macro that runs when we open Attachmate.


Code:
Shell("cmd.exe /c j: \\devicename /user:username password")

All I was missing from my original post was the "/c".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top