×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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.

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

(OP)
Still working on this one with no progress... But I can't give up.

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

(OP)
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.

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

(OP)
I'm not sure what I was thinking with the "Shell". Anyway, below is today's progress. Now I have two questions....What object type do I need to use?? Will "bWaitOnReturn = True" work to let CMD process the like before moving onto the next? Will this section correctly close and end CMD?


CODE -->

'Declare the CMD as Object
        Dim xCMD As Object
        Set xCMD = CreateObject("something.something")
        xCMD.Open FileName:="C:\Windows\System32\cmd.exe"
        xCMD.Visible = True
        bWaitOnReturn = True
        
        
'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
'--------------------------------------------------------------------------------

xCMD.quit
Set xCMD = nothing

	System.TimeoutValue = OldSystemTimeout
End Sub 

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

please excuse me for asking, but exactly what are you trying to accomplish?

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

(OP)
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".

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close