{"id":2120,"date":"2021-05-25T00:27:49","date_gmt":"2021-05-25T00:27:49","guid":{"rendered":"https:\/\/dft.wiki\/?p=2120"},"modified":"2026-06-08T22:46:39","modified_gmt":"2026-06-09T02:46:39","slug":"vbscript-cheat-sheet","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=2120","title":{"rendered":"VBScript Cheat Sheet"},"content":{"rendered":"<p>Message Box Syntax<\/p>\n<pre>Int = MsgBox(prompt[,buttons][,title][,helpfile,context])<\/pre>\n<p>Message Box Responses \/ Button Values<\/p>\n<pre>1 = vbOK\r\n2 = vbCancel\r\n3 = vbAbort\r\n4 = vbRetry\r\n5 = vbIgnore\r\n6 = vbYes\r\n7 = vbNo<\/pre>\n<p>Message Box Types<\/p>\n<pre>0 = vbOKOnly\r\n1 = vbOKCancel\r\n2 = vbAbortRetryIgnore\r\n3 = vbYesNoCancel\r\n4 = vbYesNo\r\n5 = vbRetryCancel\r\n16 = vbCritical\r\n32 = vbQuestion\r\n48 = vbExclamation\r\n64 = vbInformation\r\n... and so on ...<\/pre>\n<p>Examples of Message Box<\/p>\n<pre>msgbox \"First Line\" &amp;vbLf&amp; \"Second Line\"\r\nmsgbox \"Message Spaced\" &amp;vbTab&amp; \"By a Tab\"<\/pre>\n<p>Input Box<\/p>\n<pre>String = InputBox(String prompt, [String title], [String default], [Integer xpos], [Integer ypos], [String helpfile], [Integer context])<\/pre>\n<p>Examples of Input Box<\/p>\n<pre>Dim name\r\nname = InputBox(\"What is your name?\", \"Title\", \"...enter your name here...\")<\/pre>\n<p>Declare Variable<\/p>\n<pre>Dim var_a, var_b, var_c<\/pre>\n<p>Debugging<\/p>\n<pre>Option Explicit\r\nOn Error Resume Next<\/pre>\n<p>Comparison Operators<\/p>\n<pre>=\r\n&lt;&gt;\r\n&lt;\r\n&gt;\r\n&lt;=\r\n&gt;=<\/pre>\n<p>Logical Operators<\/p>\n<pre>And\r\nOr\r\nNot\r\nXor (Not + Or)<\/pre>\n<p>Concatenation Operators<\/p>\n<pre>+\r\n&amp;<\/pre>\n<p>Arithmetic Operators<\/p>\n<pre>+\r\n-\r\n*\r\n\/\r\n% (Remainder of Division)\r\n^ (Exponentiation)<\/pre>\n<p>Comment Operator<\/p>\n<pre>' this line will not be executed<\/pre>\n<p>Conditional IF<\/p>\n<pre>If var_a=1 Then msgbox \"One\", vbInformational<\/pre>\n<pre>If var=1 Then\r\n msgbox \"One.\"\r\nElseIf var=2 Or var=3 Then\r\n msgbox \"Two or Three.\"\r\nElse\r\n msgbox \"Not One, Two, or Three.\"\r\nEnd If<\/pre>\n<p>Select Case<\/p>\n<pre>Select Case var\r\nCase \"1\"\r\n MsgBox \"Banana\"\r\nCase \"2\"\r\n MsgBox \"Orange\"\r\nEnd Select<\/pre>\n<p>Do Loop<\/p>\n<pre>Do\r\n MsgBox \"Infinite Looping\"\r\nLoop<\/pre>\n<p>Ending a Do Loop<\/p>\n<pre>Exit Do<\/pre>\n<p>Do Loop Until \/ While \/ For<\/p>\n<pre>Do Until a = 10\r\n MsgBox \"Infinite Looping\"\r\n i = a + 1\r\nLoop<\/pre>\n<pre>Do\r\n MsgBox \"Infinite Looping\"\r\n i = a + 1\r\nLoop Until a = 10<\/pre>\n<pre>Do While a &lt;= 10\r\n MsgBox \"Infinite Looping\"\r\n i = a + 1\r\nLoop<\/pre>\n<pre>For i = 1 to 10\r\n MsgBox i\r\nNext<\/pre>\n<pre>For Each i In array\r\n MsgBox i\r\nNext<\/pre>\n<p>Creating Objects<\/p>\n<pre>Set obj = CreateObject(\"wscript.shell\")\r\nobj.run \"cmd.exe\"\r\nobj.sendkeys \"exit\"\r\nobj.sendkeys \"{ENTER}\"\r\nobj.sendkeys \"(% )(N)\"    ' types Alt+Space then N to minimize the window<\/pre>\n<p>Executing Shell Commands<\/p>\n<pre>CreateObject(\"wscript.shell\").run \"calc.exe\"\r\nCreateObject(\"wscript.shell\").run \"c:\\file.txt\"\r\nCreateObject(\"wscript.shell\").run \"c:\\folder\\\"\r\nCreateObject(\"wscript.shell\").run \"\"\"c:\\folder with space\\\"\"\"\r\nCreateObject(\"wscript.shell\").run \"c:\\users\\%username%\\Desktop\"\r\ngetPath = CreateObject(\"wscript.shell\").specialFolders(\"Desktop\")<\/pre>\n<p>Special Folders List<\/p>\n<pre>AllUsersDesktop\r\nAllUsersStartMenu\r\nAllUsersPrograms\r\nAllUsersStartup\r\nDesktop\r\nFavorites\r\nFonts\r\nMyDocuments\r\nNetHood\r\nPrintHood\r\nPrograms\r\nRecent\r\nSendTo\r\nStartMenu\r\nStartup\r\nTemplates<\/pre>\n<p>Executing Internet Explorer Commands<\/p>\n<pre>CreateObject(\"InternetExplorer.Application\").navigate \"https:\/\/myip.com\"\r\nCreateObject(\"InternetExplorer.Application\").visible = True\r\nCreateObject(\"InternetExplorer.Application\").statusbar = False\r\nCreateObject(\"InternetExplorer.Application\").toolbar = False\r\nCreateObject(\"InternetExplorer.Application\").width = 1024\r\nCreateObject(\"InternetExplorer.Application\").height = 768\r\nCreateObject(\"InternetExplorer.Application\").top = 0\r\nCreateObject(\"InternetExplorer.Application\").left = 0\r\nCreateObject(\"InternetExplorer.Application\").resizable = False\r\nCreateObject(\"InternetExplorer.Application\").fullscreen = 1\r\n\r\nDo While CreateObject(\"InternetExplorer.Application\").busy\r\n WScript.Sleep 500\r\nLoop\r\n\r\nCreateObject(\"InternetExplorer.Application\").document.all.item(\"user\").value = \"username\"\r\nCreateObject(\"InternetExplorer.Application\").document.all.item(\"pass\").value = \"password\"\r\nCreateObject(\"InternetExplorer.Application\").document.all.item(\"form\").submit<\/pre>\n<p>File System Commands<\/p>\n<pre>CreateObject(\"Scripting.FileSystemObject\").fileExists(\"image.jpg\")\r\nCreateObject(\"Scripting.FileSystemObject\").folderExists(\"c:\\users\")\r\nCreateObject(\"Scripting.FileSystemObject\").copyFile \"c:\\origin\\*.zip\", \"c:\\destiny\\\"\r\nCreateObject(\"Scripting.FileSystemObject\").moveFolder \"c:\\origin\\\", \"c:\\destiny\\\"\r\nCreateObject(\"Scripting.FileSystemObject\").moveFile \"c:\\dir\\file.zip\", \"c:\\dir\\renamed.zip\"\r\nCreateObject(\"Scripting.FileSystemObject\").fileExists(\"c:\\dir\\file.zip\")\r\nCreateObject(\"Scripting.FileSystemObject\").createTextFile \"c:\\dir\\file.txt\"\r\nCreateObject(\"Scripting.FileSystemObject\").createFolder \"c:\\dir\\\"\r\nCreateObject(\"Scripting.FileSystemObject\").deleteFolder \"c:\\dir\\\"<\/pre>\n<p>Manipulating Files<\/p>\n<pre>Dim file, file2\r\nConst Read = 1, Write = 2, Append = 8\r\n\r\nSet file = CreateObject(\"Scripting.FileSystemObject\").openTextFile(\"c:\\dir\\file.txt\", Read)\r\n\r\nfile.Read(5)\r\nfile.ReadLine\r\nfile.ReadAll\r\nfile.AtEndOfStream\r\n\r\nfile.Close\r\n\r\nSet file2 = CreateObject(\"Scripting.FileSystemObject\").openTextFile(\"c:\\dir\\file.txt\", Write)\r\n\r\nfile2.Write \"string\"\r\nfile2.WriteLine\r\nfile2.WriteBlankLines(3)\r\n\r\nfile2.Close\r\n\r\nSet file3 = CreateObject(\"Scripting.FileSystemObject\").getFile(\"c:\\dir\\file.txt\")\r\n\r\nfile3.size\r\nfile3.type\r\nfile3.path\r\nfile3.drive\r\nfile3.attributes\r\nfile3.attributes = file3.attributes + 1\r\nfile3.dateCreated<\/pre>\n<p>File Attributes<\/p>\n<pre>1 = Read Only\r\n2 = Hidden\r\n4 = System\r\n32 = Archive<\/pre>\n<p>WScript Commands<\/p>\n<pre>WScript.Quit\r\nWScript.Sleep 500\r\nWScript.ScriptName\r\nWScript.ScriptFullName\r\nWScript.CurrentDirectory<\/pre>\n<p>Commands<\/p>\n<pre>Boolean = IsNumeric(var)\r\nInt = Len(var)\r\nString = Right(var, 5)\r\nString = Left(var, 5)\r\nReplace(\"Hello All!\", \"All\", \"You\")\r\nMid(\"Hello All!\", 7, 3)\r\nArray = Split(\"Hello All!\", \" \")\r\nInt = InStr(\"Hello All!\", \"All\")\r\nIsEmpty(var)\r\nIsNumeric(var)\r\nIsObject(var)\r\nIsNull(var)\r\nIsDate(var)\r\nIsArray(var)\r\nVarType(var)\r\nTypeName(var)\r\nLCase(var)\r\nUCase(var)\r\nTrim(var)\r\nLTrim(var)\r\nRTrim(var)\r\nIsInArray(array, \"A\")\r\nAbs(-10)\r\nInt(1.7)\r\nCInt(\"30\")\r\nRound(1.7)\r\nFormatNumber(999999999, 2)\r\nFormatCurrency(999999999, 2)\r\nFormatPercent(0.99, 2)\r\nFormatDateTime(\"31-12-2000\", vbGeneralDate)\r\nFormatDateTime(\"31-12-2000\", vbLongDate)\r\nFormatDateTime(Time(), vbLongTime)\r\nSpace(15)\r\nString(20,\"-\")\r\nStrReverse(\"123456789\")<\/pre>\n<p>Subroutines<\/p>\n<pre>Sub subName(var)\r\n MsgBox var\r\nEnd Sub\r\n\r\nCall subName(\"Hello!\")<\/pre>\n<p>With Command<\/p>\n<pre>With CreateObject(\"wscript.shell\")\r\n .run \"calc.exe\"\r\nEnd With<\/pre>\n<p>Functions<\/p>\n<pre>Function funcName(var1, var2)\r\n Dim sum\r\n sum = var1 + var2\r\n funcName = sum\r\nEnd Function<\/pre>\n<p>Arguments Through Command Prompt<\/p>\n<pre>Dim args, arg\r\n\r\nSet args = WScript.Arguments\r\n\r\nFor Each arg in args\r\n MsgBox arg\r\nNext<\/pre>\n<p>Arrays<\/p>\n<pre>array1 = Array(0,1,2,3,4,5,6,7,8,9)\r\n\r\narray2 = Array(\"a\",\"1\",\"abc\",\"y z\")\r\n\r\narray3(0) = 31\r\narray3(1) = 12\r\narray3(2) = 2000\r\njoin = Join(array3, \"\/\")      ' returns 31\/12\/2000\r\n\r\nFor i = LBound(array1) To UBound(array1)\r\n MsgBox array1(i)\r\nNext\r\n\r\narrayFiltered = Filter(array2, \"a\")     ' returns only fields containing \"a\"<\/pre>\n<p>Classes<\/p>\n<pre>Class className\r\n\r\n Private var1\r\n Public var2\r\n Dim var3\r\n\r\n Sub Class_Initialize()\r\n  ' runs automatically when the class is initialized\r\n End Sub\r\n\r\n Private Sub Class_Terminate()\r\n  ' runs automatically when the class is terminated\r\n End Sub\r\n\r\n Property Let var\r\n  var1 = var\r\n End Property\r\n\r\n Property Get var\r\n  var = var1\r\n End Property\r\n\r\n Function getAbs\r\n  getAbs = abs(var1)\r\n End Function\r\n\r\nEnd Class\r\n\r\nSet num = New className\r\nnum.var = -123\r\nMsgBox num.getAbs<\/pre>\n<p>Manipulating the Windows Registry<\/p>\n<pre>Set obj = CreateObject(\"WScript.Shell\")\r\n\r\nMsgBox obj.RegRead(\"HKEY_Current_User\\Control Panel\\Desktop\\Wallpaper\")\r\nMsgBox obj.RegWrite(\"HKCU\\Control Panel\\Desktop\\Wallpaper\", \"c:\\dir\\image.jpg\")\r\nMsgBox obj.RegDelete(\"HKEY_Current_User\\Control Panel\\Desktop\\Wallpaper\")<\/pre>\n<p>Regular Expressions<\/p>\n<pre>Dim str\r\nstr = \"Is your name Bob?\"\r\n\r\nSet name = New RegExp\r\nname.Pattern = \"Bob\"\r\nname.IgnoreCase = True      ' default is False\r\nname.Global = True          ' default is False\r\n\r\nIf name.Test(str) Then\r\n String = name.Replace(str, \"John\")\r\nElse\r\n MsgBox \"Bob not found in the original string\"\r\nEnd If\r\n\r\nnumOfMatches = name.Execute(str).Count\r\nvalueOfTheMatch = name.Execute(str).Item(0).Value\r\nvalueOfTheSubmatch = name.Execute(str).Item(0).Submatches(1)<\/pre>\n<p>Environmental Variables<\/p>\n<pre>Dim env\r\nSet env = CreateObject(\"WScript.Shell\")\r\n\r\ntempFolder = env.Environment(\"User\").Item(\"TEMP\")\r\nfullPath = env.ExpandEnvironmentStrings(tempFolder)\r\n\r\nfullPath = env.ExpandEnvironmentStrings(\"%temp%\")\r\n\r\nenv.Environment(\"User\").Item(\"newVariable\") = 999\r\nMsgBox env.Environment(\"User\").Item(\"newVariable\")\r\nenv.Environment(\"User\").Remove(\"newVariable\")<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Message Box Syntax Int = MsgBox(prompt[,buttons][,title][,helpfile,context]) Message Box Responses \/ Button Values 1 = vbOK [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,7],"tags":[],"class_list":["post-2120","post","type-post","status-publish","format-standard","hentry","category-programming","category-web"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/2120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2120"}],"version-history":[{"count":8,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/2120\/revisions"}],"predecessor-version":[{"id":5730,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/2120\/revisions\/5730"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}