Problem with SHELL function!!! (1 Viewer)

bokarinho

Registered User.
Local time
Today, 02:05
Joined
Mar 31, 2010
Messages
38
Hello,

I am new to the forum, i am a vb programmer and i at current i am trying to built a class for my project. Inside the class i have some private members, a message string type that i fill it with info. My goal is to send messages across the network with the msg.exe utility that all windows support. I am working as a domain member with full previledges and my database is local in my machine. Well the problem is the following. When i go to my C:\Windows\system32 folder i find the msg.exe file. Also when i do start->run->cmd and type msg.exe and the correct parameters it also works. This does not happend when i try to call it from my access module.
Although it starts the command prompt and creates the bat file, it goes into the C:\Windows\System32 folder but it seems that there is no msg.exe there. But in graphic enviroment it exists. I noticed after many tries that when in the dos console that starts from vba i create a file, a simple txt, that does not being created in the C:\Windows\System32 gui folder as i cannot find it. It seems that vb sees another C:\Windows\system32 folder that does not have msg.exe and is diffirent from mine in the computer i work. The code is the following:

PHP:
Option Compare Database
Option Explicit
Option Base 0
'Max Msg Size.
Const Sz = 128
'Class members.
'Sets the message to be sent to the domain users with the application open.
Private Msg As String
Public Property Get Message() As String
    Message = Msg
End Property
Public Property Let Message(MsgText As String)
    Msg = IIf(Len(MsgText) > Sz, vbNullString, MsgText)
End Property
'Send the message using the shell function.
Public Static Sub SendMsg(ByVal CmpName As String, Optional cmdFullPath As String)
'Create the command that shell will execute.
    Dim Cmd As String
    Dim Filename As String
    Dim outPutFile As Variant
    Dim ret As Variant
    Cmd = "C:\Windows\System32\msg.exe /SERVER:" & CmpName & Chr(32) & "console" & Chr(32) & Msg
    Filename = "Messenger.bat"
    'Change the directory.
    'ChDir ("C:\Windows\System32")
    'Get a safe number.
    outPutFile = FreeFile()
    'Create the bat file to hold the command.
    Open Application.CurrentProject.Path & "\" & Filename For Output As #outPutFile
    'Write the command to the file.
    Print #outPutFile, Cmd
    'Close file.
    Close #outPutFile
    'Run the command.
    ret = Shell("cmd.exe /k " & Application.CurrentProject.Path & "\" & Filename, vbNormalFocus)
    'Delete file.
    Kill Application.CurrentProject.Path & "\" & Filename
End Sub

The bat file that is created in my desktop runs with double click(before is destroyed in the vba) but does not run with vba. It says that msg.exe cannot be found.

Thanks for the help.
 

ghudson

Registered User.
Local time
Yesterday, 19:05
Joined
Jun 8, 2002
Messages
6,195
There are VBA search and find commands that you can use to find the file. Are you sure you can send network messages for I believe that Microsoft turned that feature off by default after Windows XP SP2 was released.
 

bokarinho

Registered User.
Local time
Today, 02:05
Joined
Mar 31, 2010
Messages
38
Yes it is possible to send broadcast messages across the domain with Vista using the msg.exe command from the command prompt. I think after googling that my problem has to do with the 64 bit OS Vista Version because there is a redirection into the syswow64 folder when a pure 32 bit app runs. Thats why msg.exe is not found. To solve the problem i have to rewrite a mine version of msg.exe that uses winapi to send message. Otherwise there is no solution.
 

DCrake

Remembered
Local time
Today, 00:05
Joined
Jun 8, 2005
Messages
8,632
Boka...
Can you provide a working solution as described please.
 

Users who are viewing this thread

Top Bottom