djburnheim
Technical User
I've been working on a small app that calls a command line exe file (see thread222-681160) and I almost have it working now but am running into two problems. Firstly the command line exe file needs to be run from the same location as a DAT file and I've tried copying this DAT file to all the locations I can think of (windows, system32, system, root) but it doesn't seem to work so I'm not sure what path is used when Shell is called? The other problem I have is with the txt output file, from what I understand OPEN should create a file if it doesn't exsist but it doesn't so I have to leave it when I'd prefer to delete it. Running the below command from a DOS prompt works everytime with no problems (assuming the DAT file exsists in the path I'm in) and creates or overwrites the txt file as is it should but I just can't get it working from VB...any suggestions???
C:\SomeDOSPath\>d:\pgen\generator txtmachinename > d:\pgen\pw.txt
[red]***code***[/red]
[blue]
Private Sub cmdGenerate_Click()
Dim strTemp As String
Dim intFile As Integer
If frmMain.txtMachineName = "" Then
MsgBox "Please Enter Machine Name First!", vbExclamation, "No Machine Name"
frmMain.txtMachineName.SetFocus
GoTo NoMachineName:
End If
strTemp = "D:\PGen\Generator" & Chr(32) & frmMain.txtMachineName & ">D:\PGen\pw.txt"
Call Shell(strTemp, 0)
intFile = FreeFile()
Open "D:\PGen\pw.txt" For Input As #intFile
Line Input #intFile, strTemp
Close #intFile
[green] 'Kill "D:\PGen\pw.txt"[/green]
frmMain.cmdAnother.Visible = True
frmMain.cmdAnother.Enabled = True
frmMain.cmdGenerate.Visible = False
frmMain.cmdGenerate.Enabled = False
frmMain.lblAdmin.Visible = True
frmMain.lblPassword.Caption = strTemp
frmMain.lblPassword.Visible = True
frmMain.lblRemember.Visible = True
frmMain.lblExample.Visible = True
frmMain.cmdClose.SetFocus
NoMachineName:
End Sub[/blue]
C:\SomeDOSPath\>d:\pgen\generator txtmachinename > d:\pgen\pw.txt
[red]***code***[/red]
[blue]
Private Sub cmdGenerate_Click()
Dim strTemp As String
Dim intFile As Integer
If frmMain.txtMachineName = "" Then
MsgBox "Please Enter Machine Name First!", vbExclamation, "No Machine Name"
frmMain.txtMachineName.SetFocus
GoTo NoMachineName:
End If
strTemp = "D:\PGen\Generator" & Chr(32) & frmMain.txtMachineName & ">D:\PGen\pw.txt"
Call Shell(strTemp, 0)
intFile = FreeFile()
Open "D:\PGen\pw.txt" For Input As #intFile
Line Input #intFile, strTemp
Close #intFile
[green] 'Kill "D:\PGen\pw.txt"[/green]
frmMain.cmdAnother.Visible = True
frmMain.cmdAnother.Enabled = True
frmMain.cmdGenerate.Visible = False
frmMain.cmdGenerate.Enabled = False
frmMain.lblAdmin.Visible = True
frmMain.lblPassword.Caption = strTemp
frmMain.lblPassword.Visible = True
frmMain.lblRemember.Visible = True
frmMain.lblExample.Visible = True
frmMain.cmdClose.SetFocus
NoMachineName:
End Sub[/blue]