Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Translate VB into C#...I don't get it!!
Closed Thread
Old 03-19-2006, 11:00 PM   #1 (permalink)
 
Junior Techie

Join Date: Sep 2005

Posts: 72

xr280xr

Default 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

xr280xr is offline  
Old 03-20-2006, 03:39 AM   #2 (permalink)
void's Avatar
 
True Techie

Join Date: Oct 2005

Posts: 198

void

Default

Use Reflector to decompile your VB code, it can then show it in C#.
void is offline  
Old 03-20-2006, 01:12 PM   #3 (permalink)
 
Junior Techie

Join Date: Sep 2005

Posts: 72

xr280xr

Default

Ok, I will try to compile the code, thanks. Can anyone else explain the fundamentals this code uses?
xr280xr is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On