We help IT Professionals succeed at work.

msg command in visual basic

CraigMan
CraigMan used Ask the Experts™
on
I'm trying to get msg command to work like net send in visual basic within microsoft access. I'm getting the error 'msg' is not recognized as an internal or external command, operable program or batch file. When browsing within the cmd window that gets created in the script, I can't find msg.exe in c:\windows\system32. However, when I open up the command prompt from the run command I can find msg.exe in c:\windows\system32. I believe the issue has to do with environment or 64 bit OS.

The code that does the actual sending is below.

Set objShell = CreateObject("WScript.Shell")
objShell.Run ("cmd /k msg * /server:" & strComputer & " " & strMessage)

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
Fully qualify the path:

objShell.Run ("cmd /k c:\windows\system32\msg.exe * /server:" & strComputer & " " & strMessage)

Open in new window

Commented:
I tested this command and the black command window popped up (WinXP):

Private Sub Form_Load()
Set objShell = CreateObject("WScript.Shell")
objShell.Run ("cmd")
End Sub
CraigManNetwork Admin

Author

Commented:
It's not a path issue. I did try the fully qualified path and it doesn't work.
Here's a link to someone with a similar issue.
http://www.access-programmers.co.uk/forums/archive/index.php/t-190786.html
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
You may need to use a runas command for this. I think the problem you are having is due to restrictions on the command prompt that is started. I think these restrictions are preventing your code from accessing the protected system folders where msg.exe resides.

The following worked for me*:

objShell.Run ("runas /user:localhost\NameOfAdminAccount ""C:\Windows\System32\cmd.exe /k C:\windows\system32\msg.exe * /server:" & strComputer & " " & strMessage & """")

Open in new window


*Note:  Change "NameOfAdminAccount" accordingly. I was prompted for a password on my system.

Commented:
@CraigMan
Do you want to send a console message via popup to a remote user or computer?
-Then you have to create a registry key first.

Here is an article describing how to modify the registry.
CraigManNetwork Admin

Author

Commented:
I believe kaufmed is corrrect about needing elevated permission. I ended up using psexec since I couldn't get runas to work correctly.

objShell.Run ("cmd /c c:\pstools\psexec -u user -p password cmd /c msg * /server:" & strComputer & " " & strMessage)