Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post

    Exclamation Visual basic: sending a command to DOS

    Hey guys im tryin to make a very basic messenger useing the DOS function "netsend". For those of you that havnt yet seen netsend, you basicly open a dos promt and type "netsend <user name of person sending to> <Message>".

    Currently I have wrote the following:

    PHP Code:
    Private Sub cmdsend_Click()
    'Make Varibles
    Dim virbname As String
    Dim virbsendto As String
    Dim virbmessage As String
    Dim all As String

    '
    Give Varible values
    virbname 
    tbname.Text
    virbsendto 
    tbsendto.Text
    virbmessage 
    tbmessege.Text
    all 
    "netsend" " " virbsendto " " virbname ":" " " virbmessage
    MsgBox all
    End Sub 
    My only problem is that i dont know how to get the send button to send the command to dos on windows 2000.

    I have used a msgbox only for testing purposes to see if the code was working correctly.

    And help please?

    Thanks for your time, Anthony

    P.S., i dont think this is possible, but is there a way that i can get the messege that is recived from the other users on the network, and place it in a lable or anythin, instead of it showing as a prompt on screen?
    Attached Files Attached Files
    Last edited by Anthony2oo4; 01-14-2005 at 04:38 PM.

  • #2
    Super Moderator
    Join Date
    May 2002
    Posts
    1,041
    Thanks
    0
    Thanked 12 Times in 12 Posts
    Use Shell:

    http://msdn.microsoft.com/library/de...vafctshell.asp

    http://msdn.microsoft.com/library/de...ts/objects.asp

    Code:
    Dim ProcID As Integer
       ' Run Calculator.
    ProcID = Shell("C:\Windows\system32\calc.exe", AppWinStyle.NormalFocus)
    ' The preceding path is for Windows XP;
    ' The Windows 2000 path is C:\WINNT\system32\calc.exe.
    HTH,

    -sage-
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000

  • #3
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post
    i may be wrong, im only a newbie, but aint integer for numbers?

    Also this aint showing me how to run dos commands

    Sorry if it does and im just stupid

  • #4
    Super Moderator
    Join Date
    May 2002
    Posts
    1,041
    Thanks
    0
    Thanked 12 Times in 12 Posts
    You could also use:

    Dim SomeVar As String

    The whole point of the code is just to provide one way that the keyword was used...

    Hence providing links to MSDN to show you other possible ways to implement it...

    -sage-
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000

  • #5
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post
    OK, thanks for the sites and the code, but i dont fully understand. What would i need to do here?

    Thanks for your help

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I once used this sort of thing but for ftp via dos. I saved the command to a dos batch file then i used the shell command to run it. I will see if i can locate some code.

    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #7
    Regular Coder
    Join Date
    Jun 2004
    Location
    Washington University in St Louis
    Posts
    117
    Thanks
    1
    Thanked 0 Times in 0 Posts
    It's been a while since I've programmed in Visual Basic, but check the MSDN documentation on MsgBox. I believe you can set other options like how many buttons will appear on the message box etc. I believe you can also specify various function to call in the eventuality one of the buttons are pressed. Or maybe it was that the call to MsgBox returns a value depending on what was clicked by the used. Again, check MSDN documentation, but if this is the case, you can use a control structure to get the program to write the command to the console.

    Again, use the Shell command. The Shell command executes a string, but returns an integer. I'm still a little fuzzy on it, but the returned value either specifies the processor id (PID) of the command you just executed or it returns 1 for successful execution and 0 for an unsuccessful execution. Be careful with the Shell command because it's a forked process, that is, it's not sequential to the rest of your code.

  • #8
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post
    Ok, well is there a way that i can get it to:

    make a bat file where the .exe file is located
    write to it
    then delete it

    ??

    Thanks for your time guys

  • #9
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post
    OK guys i think im getting some where

    PHP Code:
    Private Sub cmdsend_Click()
    'Make Varibles
    Dim virbname As String
    Dim virbsendto As String
    Dim virbmessage As String
    Dim all As String

    '
    Give Varible values
    virbname 
    tbname.Text
    virbsendto 
    tbsendto.Text
    virbmessage 
    tbmessege.Text
    all 
    "netsend" " " virbsendto " " virbname ":" " " virbmessage
    tbmessege
    .Text Delete
    Open App
    .Path "\run.bat" For Output As #1
    Print #1, all
    Close #1
    Shell (App.Path "\run.bat")
    End Sub 
    I dont know if the shell part is correct and also, what code would i use to delete the run.bat file after it has been executed.

    Thanks again

  • #10
    Regular Coder
    Join Date
    Jun 2004
    Location
    Washington University in St Louis
    Posts
    117
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Shell ("del " & App.Path & "\run.bat")

    But if your batch file is long, you need to make sure that the batch file is finished running before you execute the above command, or else you might get strange errors. Use a while loop that will test some sort of condition that will exist after the batch file finishes executing, and the moment it detects this, use the above:

    While (TEMINATION CONDITION)
    End While
    Shell("del " & App.Path & "\run.bat")

    It's in pseudo code since I don't remember the exact syntax.
    Last edited by obiwanjabroni; 01-15-2005 at 08:57 PM.

  • #11
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post
    Well the bat file aint gonna have no more than say:

    netsend jjones hello mate hows it goin?
    so hopefully this wont be a problem

    is there a way i can delay the script execution for like 1 sec.

    your soloution would probibly work great but me being a newbie, i aint got a clue on how to fill in the missing parts. Unless someone else can

    Thanks again

  • #12
    Regular Coder
    Join Date
    Jun 2004
    Location
    Washington University in St Louis
    Posts
    117
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Okay, well, create a timer class with an interval of 1000 (milliseconds) and leave it disabled. Once you run the shell command to execute the batch, activate the timer. Put the code inside the timer to delete the file and it should all be dandy.

  • #13
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post
    Ok, iv found a way around the problem of if the file is getting used, it cant delete stated above. here is my new code.

    PHP Code:
    Private Sub cmdsend_Click()
    'Make Varibles
    Dim virbname As String
    Dim virbsendto As String
    Dim virbmessage As String
    Dim all As String
    Dim location As String

    '
    Give Varible values
    location 
    App.Path "\run.bat"
    virbname tbname.Text
    virbsendto 
    tbsendto.Text
    virbmessage 
    tbmessege.Text
    all 
    "netsend" " " virbsendto " " virbname ":" " " virbmessage
    tbmessege
    .Text Delete

    'Open the file if it exists, if not, create it.
    Open location For Output As #1

    '
    Write the messege into the file
    Print #1, all
    Close #1

    'Send the file
    Shell (location)

    End Sub

    Private Sub Command1_Click()
    '
    Delete the file run.bat
    Shell 
    ("del " App.Path "\run.bat")
    End
    End Sub

    Private Sub Form_Load()
    Create the file run.bat
    Open App
    .Path "\run.bat" For Output As #1
    Close #1
    End Sub 
    Now my last problem is that it wont delete the file on clicking the exit button (which is command1). It givens me an error of "Can't find file".

    I dont mean to sound pussy or nothing but i need this file by the end of tomorrow at about 8PM (its 11:30PM now).

    So if anyone can help me on this last problem, then i would be very happy

    Thanks for all your help

  • #14
    Regular Coder
    Join Date
    Jun 2004
    Location
    Washington University in St Louis
    Posts
    117
    Thanks
    1
    Thanked 0 Times in 0 Posts
    If you can, try printing out the contents of App.Path to another msgbox. I had a problem once with VB where it would reset the base directory while changing subs. Is App.Path an absolute path (C:\blah\blah) or a relative path (.\blah\blah). The error you are getting is related to this pathing issue. Check this first before I give any solutions because I'm not sure of the "official" way around this error, although I do know of a workaround solution that's more involved (but is better for systems since it won't clutter the registry).

  • #15
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post
    ok i fixed it, all works great now. Instead of:

    PHP Code:
    Delete the file run.bat
    Shell 
    ("del " App.Path "\run.bat")
    End 
    i used:

    PHP Code:
    Dim location As String
    location 
    App.Path "\run.bat"
    Kill location 
    And that workede great. I'd like to that all of your for the work that was placed into here. And for your time



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •