Click here to Skip to main content
Click here to Skip to main content

47 Useful Windows Vista Command-Line Utilities

By , 25 Jan 2009
 
Prize winner in Competition "Best VB.NET article of January 2009"
VistaCommands

Introduction

Have you ever tried to find a specific app in Vista, and when you did find it, how many mouse clicks did it take you to get there? 2, 3,...10? how many? If this has happened to you, then this is what you need. This app has 47 of the most commonly used command line functions(Example: RunDll32.exe, shell32.dll, Control_RunDll, appwiz.cpl, 0). This brings up the Add/Remove Programs dialog form. Copy and Paste this in your Start, Search box (and press the Enter key) to see what happens.

Typing these command lines and using multiple mouse clicks gets a little tiresome when trying to get to a specific point in the Vista arsenal of apps. So, I put all 47 commands in button click events.

Background

This program is not what I had intended. I was searching the net for a list of .NET DLLs and all their functions when I came across this site which can be viewed here. This site has a few tips-n-tricks and the 47 command lines that I use in the program.

All the command lines use 'RunDll32.exe' as a starting point, then the arguments list follows. The arguments consist of a few *.dll and *.cpl files that are all located in the 'C:\Windows\System32\' folder.

Problems... Always Problems

The first and only problem I came across was 'How do I execute these command lines in a button_click event?' I am not well versed in VB, but, I am learning. After a few failures and racking my brain, I decided to check out the Process Component in the tool box. I searched the properties and saw the 'Arguments, FileName, and Working Directory properties.' This was everything I needed to execute the command lines. The code is given below:

Public Class frmUtilities
    Inherits Form
    Dim fileArgs As String
    Dim path As String = "C:\Windows\System32\"

    Private Sub btnAddRemove_Click(ByVal sender As System.Object, ByVal e As 

System.EventArgs) Handles btnAddRemove.Click
        fileArgs = "shell32.dll,Control_RunDLL appwiz.cpl,,0"
        cmdProcess.StartInfo.Arguments = fileArgs
        cmdProcess.StartInfo.WorkingDirectory = path
        cmdProcess.StartInfo.FileName = "RunDll32.exe"
        cmdProcess.Start()
        cmdProcess.WaitForExit()
        Me.Focus()
        Me.Show()
    End Sub

    Private Sub btnContAdvisor_Click(ByVal sender As System.Object, ByVal e 

As System.EventArgs) Handles btnContAdvisor.Click
        fileArgs = "msrating.dll,RatingSetupUI"
        cmdProcess.StartInfo.Arguments = fileArgs
        cmdProcess.StartInfo.WorkingDirectory = path
        cmdProcess.StartInfo.FileName = "RunDll32.exe"
        cmdProcess.Start()
        cmdProcess.WaitForExit()
        Me.Focus()
        Me.Show()
    End Sub
    'Continues on
    'with the rest
    'of the 47 button-click events.
End Class 

CAUTION

All the Delete button click events 'DO NOT' bring up any dialog windows. They start automatically. Be careful when using these click events. Make back-ups of all your files and stuff you will want to keep. An ounce of prevention... you know the rest.

WINDOWS XP USERS: You will have to do some digging on your own to find the correct '*.cpl' files to use in some of these. Vista uses 'inetcpl.cpl' and XP might use 'inet.cpl'. I'm not sure about the exact file name so do some research on this subject before use.

UPDATES

I just added some message boxes for the delete buttons giving you a choice to delete or not to delete. I also fixed the Internet Options fileArgs to work correctly and I disabled the Open With button because it had no use in this program. Special thanks goes to Hans Dietrich for his idea on the message box implementation.

History

  • 25th January, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

rspercy65
Retired
United States United States
Member
I am currently retired.
I have no degree but I have some programming experience
when I was in college(Cobol, Pascal).
 
My accomplishments thus far are;
Best VB.Net article for January(2009)
Best VB.Net article for July(2009)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralHardcoded System PathmemberTapsnapper28 Jan '09 - 7:10 
Hi. Nice program. I have one issue though that you may want to address; you have hardcoded the path to the windows system directory. This is ok if the user has indeed installed windows on the C: drive. However, in the case of a dual boot configuration it cannot be guaranteed that the system folder will reside on C:. I have a threeway boot configuration of XP, Vista, and Windows 7beta, all on different partitions.
 
There is an article at this URL http://vbnet.mvps.org/index.html?code/system/windirs.htm[^] that explains how to obtain the current system folder path. Please do not think that I am trying to insult your intelligence if you already know how to find the system folder.
 
I was always told that whenever I wrote program code "never assume anything with regard to the users' setup configuration as there will always be one user who has altered their configuration from the norm."
GeneralRe: Hardcoded System Pathmemberrspercy5828 Jan '09 - 7:33 
I think I know what you are talking about. Code would look something like this...WinExec("%windir%\system32\control.exe ........", SW_NORMAL)
 
rspercy
1 + 1 = 186,440....Depending on the species.

GeneralRe: Hardcoded System PathmemberTobiasP29 Jan '09 - 9:43 
I do not use VB myself, but it appears to me that the method used in the linked article is for pre-VB.NET versions of the language (it was originally written 12 years ago) while the project in this article is a modern VB.NET project. In VB.NET, I assume Environment.GetFolderPath(Environment.SpecialFolder.System) is the most simple way to retrieve the path to the system folder.
GeneralRe: Hardcoded System PathmemberTapsnapper29 Jan '09 - 11:05 
Yes, you are correct. I have just tried your method and it works fine. I'm relatively new to VB.net and consequently didn't know the environment class existed.
GeneralRe: Hardcoded System Pathmemberrspercy5829 Jan '09 - 12:51 
I am creating a new version with all control panel apps in it. I have the most used categorized and the last one is all the apps. I will have to try this.
THNX for the tip.
 
rspercy
1 + 1 = 186,440....Depending on the species.

GeneralRe: Hardcoded System PathmemberTapsnapper30 Jan '09 - 4:04 
If you use this code Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.System) inplace of Dim path As String = "C:\windows\system32\" this will solve the potential hardcoded path problem.
 
One other thing I noticed in your code that is unnecessary is in your msgbox answer code. You are converting an integer return value to a string ans = CStr(MsgBox("Are you sure you want to delete these files?", MsgBoxStyle.YesNo, "Ready to Delete Files?")) and then converting that string to a double to check the return value; If CDbl(ans) = vbYes Then
 
This isn't needed. the easiest way to do this is either to declare ans as an integer because that is what the msgbox function returns and compare this to vbYes; see this link http://msdn.microsoft.com/en-us/library/139z2azd(VS.80).aspx[^] Or to do an explicit comparison without declaring the ans variable.
 
So your code would look like this in the first example
 
Dim ans As Integer
....
....
....
 
Private Sub btnDeleteTIF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteTIF.Click
ans = MsgBox("Are you sure you want to delete these files?", MsgBoxStyle.YesNo, "Ready to Delete Files?"))
If ans = vbYes Then
fileArgs = "InetCpl.cpl,ClearMyTracksByProcess 8"
cmdProcess.StartInfo.Arguments = fileArgs
cmdProcess.StartInfo.WorkingDirectory = path
cmdProcess.StartInfo.FileName = "RunDll32.exe"
cmdProcess.Start()
cmdProcess.WaitForExit()
 
Me.Show()
Else
MessageBox.Show("Process Cancelled!")
Exit Sub
End If
End Sub
 

 
in the second example you can do an explicit comparison using
 
Private Sub btnDeleteTIF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteTIF.Click
 
If MsgBox("Are you sure you want to delete these files?", MsgBoxStyle.YesNo, "Ready to Delete Files?") = vbYes Then
fileArgs = "InetCpl.cpl,ClearMyTracksByProcess 8"
cmdProcess.StartInfo.Arguments = fileArgs
cmdProcess.StartInfo.WorkingDirectory = path
cmdProcess.StartInfo.FileName = "RunDll32.exe"
cmdProcess.Start()
cmdProcess.WaitForExit()
 
Me.Show()
Else
MessageBox.Show("Process Cancelled!")
Exit Sub
End If
End Sub

 
There is also no need for the Exit Sub statement in the Else clause. The Sub will be exited after the Messagebox.Show statement anyway. You would only need the Exit Sub if you were doing more processing after the Endif statement and didn't want this to be processed once the logic was inside the else clause.
 
Regards, Paul
GeneralRe: Hardcoded System Pathmemberrspercy5830 Jan '09 - 5:01 
THNX. I am fairly new to VB. I have been programming for about 6 months now. I am learning by doing as I dont have any books on the subject. I visit this site quite often for info.
 
I have redone the program and I implimented the Environment.GetFolderPath(...) in the program and it added 3.2 meg to my program. Now, I cannot upload it to the site because it is now to big. The site only allows 6.0 meg and my program is 7.312 megs.
I did a real nice job on it too. I also added ...
(If MsgBox("Are you sure you want to delete these files?", MsgBoxStyle.YesNo, "Ready to Delete Files?") = vbYes Then...) this code you that you left and it works a lot better. The Environment.GetFolderPath(...) is also a lot faster.
 
Once again, THNX for the Lesson.
 
rspercy
1 + 1 = 186,440....Depending on the species.

GeneralRe: Hardcoded System PathmemberTapsnapper30 Jan '09 - 6:16 
No problem. If you want to email me your email address I can send you an eBook on VB.net programming which may be useful to you. You can always email me a copy of your new source code as well; I'd be interested in seeing how you've implemented the changes. My email address is paulwilcox@ymail.com. This is my public email address.
GeneralRe: Hardcoded System Pathmemberrspercy5830 Jan '09 - 7:06 
THNX. I'll zip it up and send you the code.
 
rspercy
1 + 1 = 186,440....Depending on the species.

GeneralRe: Hardcoded System PathmemberShane Story6 Feb '09 - 4:15 
something must be wrong.. An with only buttons for an interface should never be 6MB.
 
I have some very sophisticated apps full of graphics that are only 2MB. Are there other screens besides the one shown for a screenshot or other reasons it is so big?
 
Shane

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 25 Jan 2009
Article Copyright 2009 by rspercy65
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid