-
shell(problem)
I am having trouble running a dos command from my VB6 app. The command I want to run is:
Code:
rundll32 printui.dll,PrintUIEntry /if /f C:\x64\DKAAT940.inf /b "PrinterA" /r \\SERVER\pphplj2100 /m "Dell Laser Printer 5210n PS"
But no matter what I try, I can not get it to shell properly from VB. If i open a cmd window and paste it in, works fine. Start->Run works fine.
Ive tried:
Shell(rundll32 printu...blah)
Shell(cmd /c rundll32 printu...blah)
Shell(start rundll32 printu...blah)
Shell(cmd /c start rundll32 printu...blah)
Shell(start cmd /c rundll32 printu...blah)
Any Ideas? printui.dll,PrintUIEntry IS invoked, but its failing somewhere. I have been stuck on this for a few days now, and I am fustrated. I have simplified this as much as i could in the VB program, just to try to get this to work. shell(textbox1.text) but no dice. I also noticed that if, in the command window I try to run "cmd /c rundll32 printu...blah" It will fail. I had thought that perhaps I need to try using escape characters, but so far, I haven't been able to figure it out. Any help would be much appreciated.
-
Re: shell(problem)
It usually works more like this:
Shell into PIPE
Code:
Option Explicit
Private Sub Form_Load()
Shell ("C:\Windows\System32\cmd.exe /c " & _
"C:\Windows\System32\ipconfig >> d:\myip.txt"), vbNormalFocus
End Sub
You probably want to use ShellExecute() though:
Code:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_HIDE As Long = 0
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Dim sSave As String, Ret As Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim sSave As String, Ret As Long
'Create a buffer
sSave = Space(255)
'Get the system directory
Ret = GetSystemDirectory(sSave, 255)
'Remove all unnecessary chr$(0)'s
sSave = Left$(sSave, Ret)
End Sub
Private Sub Command1_Click()
ShellExecute Me.hwnd, "Open", sSave & "CMD.exe", " /c dir c: > D:\Myfile.txt", "D:\", SW_SHOWNORMAL
End Sub
-
Re: shell(problem)
You can write the commands to a bat file then use shell to execute the bat file.
-
Re: shell(problem)
It could simply be a problem of the quotes which are embedded in the command string.
You have to embed the whole string which is the shell command in quotes. So any quotes which are embedded in this string have to be doubled to stay in place when the command is passed to the command interpreter.
Try:
Code:
Shell "rundll32 printui.dll,PrintUIEntry /if /f C:\x64\DKAAT940.inf /b ""PrinterA"" /r \\SERVER\pphplj2100 /m ""Dell Laser Printer 5210n PS"""
-
Re: shell(problem)
Thank you all for your suggestions. I have tried each of them with some success. (each method works!) BUT... So far I have had no luck getting rundll32 to do its magic. Each time I get "Operation could not be completed".
I have narrowed it down to not being a VB or batch file issue... so ill end my questions now. Thank you very much for the help!