Hello guys, this is just a random tutorial I decided to share with you. That was just my school project, nothing special, just some shit to get an A mark. The only interesting thing in this project is its construction. So let me tell you how to do this...
PLEASE, ALL MEMBERS WHO ARE BLUE/YELLOW/PURPLE YOU BETTER DON'T READ THIS THREAD TO BE NOT RAGING ;D
Some more offtopic: this tut is made for complete NOOBS who know NOTHING like my 9-yo bro. 70% of itsmods are such people. So no messages "we all know that, kinda useless tut". thats why all skilled coders better close that page.
Okay, now once you are ready to start - let's do this.
First of all, we are making a console application in VB.NET (I was using 4.5 Framework, although all these commands will work on older versions either). At very beginning of our Module1 let's make few imports:
Code:
Imports Microsoft.Win32
Imports System
Imports System.IO
Imports System.Runtime.CompilerServices
Nice, now let's pass over to fundamental functions. I want to notice that I made my tool in NOT STANDARD way, invented by myself (I don't care if somebody made it before me, ALL OF THESE CODES were written only and only by me, without even internet connection while writing). It is a bit specific, but it works
Okay, firstly declare new string "Decision". Make new subs output & stext & input & info:
Code:
Sub output()
Console.ResetColor()
End Sub
Sub stext()
Console.ForegroundColor = ConsoleColor.Red
End Sub
Sub input()
Console.ForegroundColor = ConsoleColor.Yellow
End Sub
Sub info()
Console.ForegroundColor = ConsoleColor.Green
End Sub
Now in main sub write Output() and (each new command goes on new line) console.title = "YOUR APP TITLE" and some introduction message. In my app:
Code:
output()
Console.Title = "PC Info - console version"
Console.WriteLine("Welcome to PC Info. This application can be used in the same way as cmd. If you want to know something about your PC - type right code and hit ENTER. To see allavailable codes type HELP and hit ENTER.")
Console.WriteLine()
Console.Write("Notice that all commands have to be typed with ")
stext()
Console.Write("lower case letters.")
Console.WriteLine()
Console.WriteLine()
Now after this we have to make sub Action() and put it after introductory part. I think the name of sub describes what it does
Code:
Sub action()
Do Until decision = "exit"
say()
com()
Loop
End Sub
This means that action command will be repeated until decision string (full explanation a bit later - in short - it is the command user types in) is "exit". Now we can see that Action() uses two new susbs - let's add them.
Code:
Sub say()
output()
Console.Write("User: ")
input()
decision = Console.ReadLine
End Sub
Now you can see that string decision is the command the user types in. We are close to the end... Let's make the com() as this sub is still remaining undeclared.
Code:
Sub com()
output()
If decision = "<YOUR-COMMAND>" Then
<YOUR CODE GOES HERE>
End if
End sub
This is the main part - user typed in the command -> it was written to string DECISION -> if decision = some specified command then something happens. Example:
Code:
Sub com()
output()
If decision = "help" Then
<ALL-AVAILABLE-COMMANDS>
End if
End sub
If you want to add more codes, just add elseif struct to com() sub and voila. Finally at the end of main() sub add
Code:
action()
If decision = "exit" Then
End
End If
You are done now! Try it, you will have a command-line app with your own commands, you can customize all my "settings" (colors, text, etc) to make your own app.
Full source code in spoiler
Code:
Imports Microsoft.Win32
Imports System
Imports System.IO
Imports System.Runtime.CompilerServices
Module Module1
Dim decision As String
Sub Main()
output()
Console.Title = "PC Info - console version"
Console.WriteLine("Welcome to PC Info. This application can be used in the same way as cmd. If you want to know something about your PC - type right code and hit ENTER. To see allavailable codes type HELP and hit ENTER.")
Console.WriteLine()
Console.Write("Notice that all commands have to be typed with ")
stext()
Console.Write("lower case letters.")
Console.WriteLine()
Console.WriteLine()
action()
If decision = "exit" Then
End
End If
Console.ReadLine() 'THIS IS GOING AT END OF CODE SO WE WILL SEE HOW IT WORKS
End Sub
Sub com()
output()
If decision = "help" Then
Console.WriteLine()
info()
Console.WriteLine("All available commands:")
output()
Console.WriteLine("clear - clears console history")
Console.WriteLine("cpu - shows wether you have x32 or x64 CPU")
Console.WriteLine("defb - shows default browser")
Console.WriteLine("drives - shows number, names, total and free space of drives")
Console.WriteLine("exit - closes this application")
Console.WriteLine("goto - open a page via default browser")
Console.WriteLine("lang - shows current language used by OS")
Console.WriteLine("memory - shows info about your PC memory (both physical and virtual)")
Console.WriteLine("mwheel - indicates whether your mouse has wheel or not")
Console.WriteLine("os - shows currently installed operating system")
Console.WriteLine("pcname - shows name of PC")
Console.WriteLine("screen - shows screen info")
Console.WriteLine("sdb - start default browser")
Console.WriteLine("time - shows local and GMT current time")
Console.WriteLine("username - displays name of PC user")
Console.WriteLine("webtest - indicates whether internet connection is available")
'-------------------NEW COMS HERE--------------------
Console.WriteLine()
'to be continued (remember: alphabet sorta.) <--- not 100%
ElseIf decision = "screen" Then
Console.WriteLine()
Dim res As String
res = My.Computer.Screen.Bounds.Right & " x " & My.Computer.Screen.Bounds.Bottom
info()
Console.Write("Resolution is ")
output()
Console.WriteLine(res)
info()
Console.Write("Device name is ")
output()
Console.WriteLine(My.Computer.Screen.DeviceName)
info()
Console.Write("Working area is ")
output()
Console.WriteLine(My.Computer.Screen.WorkingArea)
Console.WriteLine()
ElseIf decision = "clear" Then
Console.Clear()
Main()
ElseIf decision = "os" Then
Console.WriteLine()
Console.WriteLine(My.Computer.Info.OSFullName)
Console.WriteLine()
ElseIf decision = "memory" Then
Console.WriteLine()
info()
Console.Write("Total physical memory: ")
output()
Console.WriteLine(My.Computer.Info.TotalPhysicalMemory)
info()
Console.Write("Available physical memory: ")
output()
Console.WriteLine(My.Computer.Info.AvailablePhysicalMemory)
Console.WriteLine()
info()
Console.Write("Total virtual memory: ")
output()
Console.WriteLine(My.Computer.Info.TotalVirtualMemory)
info()
Console.Write("Available virtual memory: ")
output()
Console.WriteLine(My.Computer.Info.AvailableVirtualMemory)
Console.WriteLine()
ElseIf decision = "username" Then
Console.WriteLine()
Console.WriteLine(My.User.Name)
Console.WriteLine()
ElseIf decision = "lang" Then
Console.WriteLine()
Console.WriteLine(My.Computer.Info.InstalledUICulture)
Console.WriteLine()
ElseIf decision = "time" Then
Console.WriteLine()
info()
Console.Write("GMT time: ")
output()
Console.WriteLine(My.Computer.Clock.GmtTime)
info()
Console.Write("Local time: ")
output()
Console.WriteLine(My.Computer.Clock.LocalTime)
Console.WriteLine()
ElseIf decision = "drives" Then
Console.WriteLine()
info()
Console.Write("Total number of drives: ")
output()
Console.WriteLine(My.Computer.FileSystem.Drives.Count.ToString)
For Each drive In My.Computer.FileSystem.Drives
Try
Console.WriteLine("{0}, {1}, {2}", drive.Name, drive.TotalSize, drive.AvailableFreeSpace)
Catch ex As Exception
'do nothing
End Try
Next
stext()
Console.WriteLine("NAME, total space, free space")
Console.WriteLine()
ElseIf decision = "keyboard" Then
Console.WriteLine()
info()
Console.Write("Caps lock is ")
If My.Computer.Keyboard.CapsLock = True Then
output()
Console.WriteLine("enabled.")
Else
output()
Console.WriteLine("disabled.")
End If
info()
Console.Write("Num lock is ")
If My.Computer.Keyboard.NumLock = True Then
output()
Console.WriteLine("enabled.")
Else
output()
Console.WriteLine("disabled.")
End If
info()
Console.Write("Scroll lock is ")
If My.Computer.Keyboard.ScrollLock = True Then
output()
Console.WriteLine("enabled.")
Else
output()
Console.WriteLine("disabled.")
End If
Console.WriteLine()
ElseIf decision = "defb" Then
Try
Console.WriteLine()
stext()
Console.WriteLine("This function DOES NOT ALWAYS WORK.")
Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Clients\StartmenuInternet")
Dim name As String = key.GetValue("")
info()
Console.Write("Default browser is ")
output()
Console.WriteLine(name)
Console.WriteLine()
Catch ex As Exception
'do nothing
End Try
ElseIf decision = "mwheel" Then
Console.WriteLine()
info()
Console.Write("Your mouse ")
output()
Dim yesno As String = "does not"
If My.Computer.Mouse.WheelExists = True Then
yesno = "has "
Else
yesno = "doesn't have "
End If
Console.Write(yesno)
info()
Console.WriteLine("a wheel.")
Console.WriteLine()
ElseIf decision = "pcname" Then
Console.WriteLine()
info()
Console.Write("Your PC name is ")
output()
Console.WriteLine(My.Computer.Name)
Console.WriteLine()
ElseIf decision = "webtest" Then
Console.WriteLine()
info()
Console.Write("Internet ")
output()
If My.Computer.Network.IsAvailable = True Then
Console.WriteLine("is available.")
Else
Console.WriteLine("is not available.")
End If
Console.WriteLine()
ElseIf decision = "cpu" Then
Dim architecture As Integer = Runtime.InteropServices.Marshal.SizeOf(GetType(IntPtr)) * 8
Select Case architecture
Case 32
Console.WriteLine()
info()
Console.Write("Your CPU is ")
output()
Console.WriteLine("x32.")
Console.WriteLine()
Case 64
Console.WriteLine()
info()
Console.Write("Your CPU is ")
output()
Console.WriteLine("x64.")
Console.WriteLine()
End Select
ElseIf decision = "sdb" Then
Console.WriteLine()
Console.WriteLine("Opening browser...")
sdb()
Console.WriteLine("Browser opened!")
Console.WriteLine()
ElseIf decision = "goto" Then
browser()
Else
Console.WriteLine()
stext()
Console.WriteLine("Wrong command! Type help to see list of right commands and check if your Caps")
Console.WriteLine("Lock is turned off - we accept only lower case letter commands.")
output()
Console.WriteLine()
End If
End Sub
Sub sdb()
If My.Computer.FileSystem.DirectoryExists(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\pcinfo") Then
'do nothing
Else
My.Computer.FileSystem.CreateDirectory(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\pcinfo")
End If
If My.Computer.FileSystem.FileExists(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\pcinfo\index.txt") Then
My.Computer.FileSystem.DeleteFile(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\pcinfo\index.txt")
If My.Computer.FileSystem.FileExists(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\pcinfo\index.html") Then
My.Computer.FileSystem.DeleteFile(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\pcinfo\index.html")
End If
Else
If My.Computer.FileSystem.FileExists(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\pcinfo\index.html") Then
My.Computer.FileSystem.DeleteFile(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\pcinfo\index.html")
End If
End If
File.Create(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\pcinfo\index.html").Dispose()
Dim sss As System.IO.StreamWriter
sss = File.CreateText(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\pcinfo\index.html")
sss.WriteLine("<html>")
sss.WriteLine()
sss.WriteLine("<head>")
sss.WriteLine("<title>PC Info home page</title>")
sss.WriteLine("</head>")
sss.WriteLine()
sss.WriteLine("<body bgcolor=""white"" text=""blue"">")
sss.WriteLine()
sss.WriteLine("<h1> PC Info </h1>")
sss.WriteLine("A simple app created by <NAME> <SURNAME> for learning purposes. It allows you to know all information about your PC.")
sss.WriteLine("<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>")
sss.WriteLine("<h1>YOU STARTED WEB-BROWSER! HERE ARE FEATURED LINKS<h1>")
sss.WriteLine("<a href=""http://www.google.com"">Google</a><br>")
sss.WriteLine("<a href=""http://www.itsmods.com"">Itsmods</a><br>")
sss.WriteLine("<a href=""http://www.<SITE>.ru""><SITE></a><br>")
sss.WriteLine("</body>")
sss.WriteLine()
sss.WriteLine("</html>")
sss.Dispose()
System.Diagnostics.Process.Start(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\pcinfo\index.html")
End Sub
Sub browser()
Console.WriteLine()
stext()
Console.WriteLine("Please enter page like GOOGLE.COM without HTTP or WWW part")
info()
Console.Write("Address: ")
input()
Dim page As String
page = Console.ReadLine
If page IsNot "" Then
System.Diagnostics.Process.Start("http://www." & page)
Else
sdb()
End If
Console.WriteLine()
End Sub
#Region "fundamental"
Sub output()
Console.ResetColor()
End Sub
Sub input()
Console.ForegroundColor = ConsoleColor.Yellow
End Sub
Sub stext()
Console.ForegroundColor = ConsoleColor.Red
End Sub
Sub say()
output()
Console.Write("User: ")
input()
decision = Console.ReadLine
End Sub
Sub action()
Do Until decision = "exit"
say()
com()
Loop
End Sub
Sub info()
Console.ForegroundColor = ConsoleColor.Green
End Sub
#End Region
End Module
Thanks for reading, I guess the explanation was not the best one, but I'm porud to share this since I made the structure myself.