Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Push a button to launch vbs.. I am a newb.. HALP!!

Status
Not open for further replies.

MrKovacic

IS-IT--Management
Nov 5, 2002
213
US
Hello all, i bet this is simple, but after over a week, i still cant to it..

I am using Microsoft visual basic 2005 express, and I am trying to make a simple program that has buttons, and at the push of a button, will execute a .vbs script i have embedded.

I tried the shell command, but it keeps saying it cant find the file specified... even though i verified it twice..

any ideas??

Thank you!!!

Mike Kovacic
 
Based on the code that you have provided, it is very difficult to suggest anything.

[vampire][bat]
 
point taken...

ok, here is the code in my vbs script:
Code:
Option Explicit
Dim objFSO, objFolder, objShell, strDirectory,WshShell,iklogname,subject,when,remedyticket,OlApp,nsNameSpace,olFolderCalendar,olEvent,olByValue
strDirectory = "c:\remtemp"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strDirectory) Then
   Set objFolder = objFSO.GetFolder(strDirectory)
else
Set objFolder = objFSO.CreateFolder(strDirectory)
end if
Set WshShell = WScript.CreateObject("WScript.Shell")
iklogname = "01234567"
If iklogname = "" Then
MsgBox ("I can not create a reminder if you don't give me a ticket number.")
Wscript.Quit 1
Else
subject = "attachment test"
when = "1"
If when = "" Then
MsgBox ("This is required!")
when = Inputbox("how many minutes until I should remind you? [1440 is 24 hours]" , "Remind me in...")
Else

DIM fso, GuyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set remedyticket = fso.CreateTextFile( "C:\remtemp\RemedyTicket " & iklogname & ".ARTask", True)
remedyticket.WriteLine("[Shortcut]") 
remedyticket.WriteLine ("Name = HPD:HelpDesk") 
remedyticket.WriteLine ("Type = 0") 
remedyticket.WriteLine ("Server = my.remedy.server") 
remedyticket.WriteLine ("Join = 0") 
remedyticket.WriteLine ("Ticket = 00000000" & iklogname) 
remedyticket.Close
END IF
Set OlApp = CreateObject("Outlook.Application")
Set nsNameSpace = OlApp.GetNamespace("MAPI")
Set olFolderCalendar = nsNameSpace.GetDefaultFolder(9) 'olFolderCalendar
Set olEvent = OlApp.CreateItem(1) 'olAppointmentItem
olEvent.Start = DateAdd("n", when, Now())
olEvent.Subject = subject
olEvent.ReminderSet = True
olEvent.ReminderMinutesBeforeStart = 1
olEvent.Attachments.Add "C:\remtemp\RemedyTicket " & iklogname & ".ARTask", _
olByValue, 1, "Test"
olEvent.Save
MsgBox ("The event has been created in your Outlook calendar. Should you need to cancel or change your reminder, it must be done through outlook.")
END IF

and here is what I have so far for my project:
Code:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        Shell("%SystemRoot%\System32\WScript.exe C:\scripts\script.vbs", vbNormalFocus)

    End Sub
End Class

Thank you!!!

Mike Kovacic
 
I believe there is a command other than Shell (which is VBA) that is used in VB.NET 2005. Let me look at and old project and I will let you know.
 
Code:
' /* Create Shell Object */
dim WSH
set WSH = createobject("WScript.Shell")
 
Thanks Chrissie!!

I found the code
Code:
Public Sub ShellandWait(ByVal ProcessPath As String)
        Dim objProcess As System.Diagnostics.Process
        Try
            objProcess = New System.Diagnostics.Process()
            objProcess.StartInfo.FileName = ProcessPath
            objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
            objProcess.Start()

            'Wait until the process passes back an exit code 
            objProcess.WaitForExit()

            'Free resources associated with this process
            objProcess.Close()
        Catch
            MessageBox.Show("Could not start process " & ProcessPath, "Error")
        End Try
    End Sub

but I dont know where to slip in the program I want to run, also, can I try to run the VBS itself, or do i have to have it run %SystemRoot%\System32\WScript.exe first?

Thank you!!!

Mike Kovacic
 
this would be the filename

%SystemRoot%\System32\WScript.exe

and rest goes here

objprocess.StartInfo.Arguments = "C:\scripts\script.vbs"

Christiaan Baes
Belgium

"My old site" - Me
 


I think i fubared it.. here is what I have so far:

Code:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim objProcess As System.Diagnostics.Process
        Try
            objProcess = New System.Diagnostics.Process()
            objProcess.StartInfo.Arguments = "%SystemRoot%\System32\WScript.exe C:\scripts\script.vbs"
            objProcess.StartInfo.FileName = ProcessPath
            objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
            objProcess.Start()

            'Wait until the process passes back an exit code
            objProcess.WaitForExit()

            'Free resources associated with this process
            objProcess.Close()
        Catch
            MessageBox.Show("Could not start process " & ProcessPath, "Error")
        End Tr

    End Sub
End Class

after this.. i swear to learn visual basic step by step

Thank you!!!

Mike Kovacic
 
So what was the error?

I think it is more like this.

objProcess.StartInfo.Arguments = "C:\scripts\script.vbs"
objProcess.StartInfo.FileName = "%SystemRoot%\System32\WScript.exe"


Christiaan Baes
Belgium

"My old site" - Me
 
Oh actually, you can use something else too.

Code:
System.Diagnostics.Process.Start(app, rptPath)
 
the error is a pop-up box that just says :

Could not start process

also in the error log im getting:

Error 1 Name 'ProcessPath' is not declared. 11 45
Error 2 Name 'ProcessPath' is not declared. 21 58



Thank you!!!

Mike Kovacic
 
I found it!! WOOHOO , I took out the args..

Here is whats working...

Code:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim objProcess As System.Diagnostics.Process
        Try
            objProcess = New System.Diagnostics.Process()
            'objProcess.StartInfo.Arguments = "C:\scripts\script.vbs"
            objProcess.StartInfo.FileName = "C:\scripts\script.vbs"
            objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
            objProcess.Start()

            'Wait until the process passes back an exit code
            objProcess.WaitForExit()

            'Free resources associated with this process
            objProcess.Close()
        Catch
            MessageBox.Show("Could not start process - Error")
        End Try

    End Sub
End Class

Thank you!!!

Mike Kovacic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top