03-19-2006, 11:00 PM
|
#1 (permalink)
|
Junior Techie Join Date: Sep 2005 Posts: 72
| Translate VB into C#...I don't get it!! Hi,
This code demonstrates what I would like to do in a C# application, but it is very confusing to me in visual basic. What it does is runs the scheduled tasks wizard. Is anyone able to explain it and/or translate the code into C#? Thanks. Quote: Code: Private Sub CommandButton1_Click()
Dim SA As Object
Dim vFolder, ItemFold, MyItemFolder, ShedulFold, SchedWizard, Verb As Object
Dim ShedulFoldX As Object
Now I created Shell object (“Shell.Application” is
ProgramID): Code: Set SA = CreateObject("Shell.Application")
Well, if you open Control Panel, you find item with name “Scheduled Tasks”.
Ah, itÂ’s just what we need. Let us do programmatically the same that we do
manually. Open Control Panel via method NameSpace of Shellobject: Code: ssfCONTROLS = 3
Set vFolder = SA.NameSpace(ssfCONTROLS)
Set ItemFold = vFolder.Items
Good, now let us enumerate all items in Control Panel till we find item with
name – “Scheduled Tasks”. OK, you are right, it will have another name for
native localized Windows (but I show now it for English-language Windows
version. Be sure if you change name to native, it will work for native
Windows): Code: Found = False
For Each MyItemFolder In ItemFold
If MyItemFolder.Name = "Scheduled Tasks" Then
Set ShedulFold = MyItemFolder.GetFolder
Found = True
Exit For
End If
Next
If Found = False Then
End
End If
And get collection of items in “Scheduled tasks” folder: Code: Set ShedulFoldX = ShedulFold.Items
And now the last step – we must find item “Add Scheduled Task”, enumerate
Verbs (that can work with this item), and do the appropriate verb. It is not a
secret that there exists only one verb for “Add Scheduled Task”, and it’s name
is “Open”: Code: For Each SchedWizard In ShedulFoldX
If SchedWizard.Name = "Add Scheduled Task" Then
Set Verbs = SchedWizard.Verbs
SchedWizard.InvokeVerb (Verbs.Item(0))
Exit For
End If
Next
| |
| |