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:
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.
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.