cluberti Posted June 17, 2010 Share Posted June 17, 2010 Description: VBscript to modify or delete the paging file from a Windows system via WMI or direct registry edit.Programming Language: VBScriptUsage: Remove the .txt extension from the attached file, and either run from cscript or double-click the .vbs.'// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'//'// NAME: setpagefile.vbs'//'// Original: http://www.cluberti.com/blog'// Last Update: 16th June 2010'//'// Comment: VBS example file for use in configuring the paging file on Windows'//'// NOTE: Provided as-is - usage of this source assumes that you are at the'// very least familiar with the vbscript language being used and'// the tools used to create and debug this file.'//'// In other words, if you break it, you get to keep the pieces.'//'// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Option ExplicitDim strComputer, strPageFileSizeInput, strPageFileNameInput, strInputDim objWMIService, objStaticPageFileItem, objDynamicPageFileItem, objShellAppDim colStaticPageFileItems, colDynamicPageFileItems, isRunning, execOutput, gErrData, bRebootNeeded, bNoStaticPageFile, bNoPageFile'// Ensure that cscript is the engine used to run this script:RunMeWithCScript()On Error Resume Next'// Configure our variables:strComputer = "."bRebootNeeded = FalsebNoStaticPageFile = TruebNoPageFile = TrueSet objShellApp = CreateObject("WScript.Shell")Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")'// Win32_PageFile is deprecated - it still (mostly) works, but Win32_PageFileSetting is not deprecated, so use that:Set colStaticPageFileItems = objWMIService.ExecQuery("SELECT * FROM Win32_PageFileSetting",,48)Set colDynamicPageFileItems = objWMIService.ExecQuery("SELECT * FROM Win32_PageFileUsage",,48)'// Execute the ChangePagingFile sub:ChangePagingFile()'// Check execution of ChangePagingFile(), and handle when "system managed" is set, or no paging file exists:If bRebootNeeded = True Then RebootSystem()Else '// Can't use WMI to create a paging file when it is "system managed" or none exists - handle this condition: If bNoStaticPageFile = True Then CheckForDynamicPagingFile() If bNoPageFile = False Then WScript.Quit Else If bNoPageFile = True Then WScript.Echo "No paging file found." WScript.Echo "" strPageFileNameInput = UserInput("Enter new pagefile name (full path and filename) - leave blank to use C:\pagefile.sys: ") strPageFileSizeInput = UserInput("Enter new pagefile size (in MB) - leave blank to keep the system with no paging file: ") '// Check to see if the user left the input blank, otherwise set up a paging file: If Not strPageFileSizeInput = "" Then If strPageFileNameInput = "" Then strPageFileNameInput = "C:\pagefile.sys" End If WScript.Echo "New pagefile file will be: " & strPageFileNameInput WScript.Echo "New pagefile size will be: " & strPageFileSizeInput & "MB" bNoStaticPageFile = False '// Change the registry to add paging file information: objShellApp.Exec("reg add ""HKLM\System\CurrentControlSet\Control\Session Manager\Memory Management"" /v PagingFiles /t REG_MULTI_SZ /d """ & strPageFileNameInput & " " & strPageFileSizeInput & " " & strPageFileSizeInput & """ /f") '// Check the return to make sure we succeeded - otherwise, tell the user why we didn't: If Not Err.Number = 0 Then gErrData = gErrData & vbCrLf & "Error writing to registry - reason: " & Err.Number & " - " & Err.Description WScript.Echo gErrData Err.Clear Else WScript.Echo "Registry edit to add " & strPageFileNameInput & " as size " & strPageFileSizeInput & "MB was successful." bRebootNeeded = True End If '// If we've made changes that have succeeded, we need to reboot - otherwise, do nothing: If bRebootNeeded = True Then RebootSystem() Else WScript.Echo "No changes made that require a reboot. Exiting script." End If Else WScript.Echo "You have elected to continue with no paging file. Exiting script." End If Else WScript.Echo "No changes made that require a reboot. Exiting script." End If End If End IfEnd IfSub ChangePagingFile() For Each objStaticPageFileItem In colStaticPageFileItems '// There's a static paging file - use WMI to make changes: bNoStaticPageFile = False bNoPageFile = False WScript.Echo " --------------------------" WScript.Echo " Current PageFile Details" WScript.Echo " --------------------------" WScript.Echo "Name: " & objStaticPageFileItem.Name WScript.Echo "InitialSize: " & objStaticPageFileItem.InitialSize WScript.Echo "MaximumSize: " & objStaticPageFileItem.MaximumSize WScript.Echo "" '// Get user input: strInput = UserInput("Enter new pagefile size (in MB) - leave blank to delete existing paging file: ") '// If the user entered a value, configure the new paging file size: If Not strInput = "" Then WScript.Echo "New pagefile size will be: " & strInput & "MB" WScript.Echo "" objStaticPageFileItem.InitialSize = strInput objStaticPageFileItem.MaximumSize = strInput objStaticPageFileItem.Put_ bRebootNeeded = True WScript.Echo " --------------------------" WScript.Echo " New PageFile Details" WScript.Echo " --------------------------" WScript.Echo "Name: " & objStaticPageFileItem.Name WScript.Echo "InitialSize: " & objStaticPageFileItem.InitialSize WScript.Echo "MaximumSize: " & objStaticPageFileItem.MaximumSize WScript.Echo "" WScript.Echo "A reboot is needed for this change to take effect." '// If the user left the input blank, delete the paging file - note that Delete and DeleteEx from Win32_PagingFile are deprecated, and '// while they'll return 0 on Windows 7, they don't actually delete the paging file. Using reg add instead, as it works just fine: Else WScript.Echo "Deleting paging file: " & objStaticPageFileItem.Name objShellApp.Exec("reg add ""HKLM\System\CurrentControlSet\Control\Session Manager\Memory Management"" /v PagingFiles /t REG_MULTI_SZ /d """" /f") '// Check the return to make sure we succeeded - otherwise, tell the user why we didn't: If Not Err.Number = 0 Then gErrData = gErrData & vbCrLf & "Error writing to registry - reason: " & Err.Number & " - " & Err.Description WScript.Echo gErrData Err.Clear Else WScript.Echo "Registry edit to remove " & objStaticPageFileItem.Name & " was successful." bRebootNeeded = True End If End If NextEnd SubSub CheckForDynamicPagingFile() For Each objDynamicPageFileItem In colDynamicPageFileItems '// There's a paging file - use WMI to make changes: bNoPageFile = False WScript.Echo "Paging file is configured for 'System managed size'" WScript.Echo "" WScript.Echo " --------------------------" WScript.Echo " Current PageFile Details" WScript.Echo " --------------------------" WScript.Echo "Name: " & objDynamicPageFileItem.Name WScript.Echo "Size: " & objDynamicPageFileItem.AllocatedBaseSize WScript.Echo "Current Usage: " & objDynamicPageFileItem.CurrentUsage WScript.Echo "" WScript.Echo "" strPageFileNameInput = UserInput("Enter new pagefile name (full path and filename) - leave blank to use C:\pagefile.sys: ") strPageFileSizeInput = UserInput("Enter new pagefile size (in MB) - leave blank to remove the paging file: ") '// Check to see if the user left the input blank, otherwise set up a paging file: If Not strPageFileSizeInput = "" Then If strPageFileNameInput = "" Then strPageFileNameInput = "C:\pagefile.sys" End If WScript.Echo "New pagefile file will be: " & strPageFileNameInput WScript.Echo "New pagefile size will be: " & strPageFileSizeInput & "MB" bNoStaticPageFile = False '// Change the registry to add paging file information: objShellApp.Exec("reg add ""HKLM\System\CurrentControlSet\Control\Session Manager\Memory Management"" /v PagingFiles /t REG_MULTI_SZ /d """ & strPageFileNameInput & " " & strPageFileSizeInput & " " & strPageFileSizeInput & """ /f") '// Check the return to make sure we succeeded - otherwise, tell the user why we didn't: If Not Err.Number = 0 Then gErrData = gErrData & vbCrLf & "Error writing to registry - reason: " & Err.Number & " - " & Err.Description WScript.Echo gErrData Err.Clear Else WScript.Echo "Registry edit to add " & strPageFileNameInput & " as size " & strPageFileSizeInput & "MB was successful." bRebootNeeded = True End If '// If we've made changes that have succeeded, we need to reboot - otherwise, do nothing: If bRebootNeeded = True Then RebootSystem() WScript.Quit Else WScript.Echo "No changes made that require a reboot. Exiting script." WScript.Quit End If '// If the user left the input blank, delete the paging file - note that Delete and DeleteEx from Win32_PagingFile are deprecated, and '// while they'll return 0 on Windows 7, they don't actually delete the paging file. Using reg add instead, as it works just fine: Else WScript.Echo "Deleting paging file: " & objDynamicPageFileItem.Name objShellApp.Exec("reg add ""HKLM\System\CurrentControlSet\Control\Session Manager\Memory Management"" /v PagingFiles /t REG_MULTI_SZ /d """" /f") '// Check the return to make sure we succeeded - otherwise, tell the user why we didn't: If Not Err.Number = 0 Then gErrData = gErrData & vbCrLf & "Error writing to registry - reason: " & Err.Number & " - " & Err.Description WScript.Echo gErrData Err.Clear Else WScript.Echo "Registry edit to remove " & objDynamicPageFileItem.Name & " was successful." bRebootNeeded = True End If End If NextEnd SubSub RebootSystem() WScript.Echo "The system will reboot in 5 seconds..." Set isRunning = objShellApp.Exec("shutdown /r /t 5 /f /d p:2:4") '// As long as shutdown.exe is running, wait: Do While isRunning.Status = 0 WScript.Sleep 100 execOutput = isRunning.StdOut.ReadAll LoopEnd SubFunction UserInput(strInput) WScript.StdOut.Write strInput & " " UserInput = WScript.StdIn.ReadLineEnd FunctionOn Error GoTo 0Sub RunMeWithCScript() Dim ScriptEngine, engineFolder, Args, arg, scriptName, argString, scriptCommand ScriptEngine = UCase(Mid(WScript.FullName, InstrRev(WScript.FullName, "\") + 1)) engineFolder = Left(WScript.FullName, InstrRev(WScript.FullName, "\")) argString = "" If ScriptEngine = "WSCRIPT.EXE" Then Dim Shell Set Shell = CreateObject("WScript.Shell") Set Args = WScript.Arguments For Each arg in Args If InStr(arg, " ") > 0 Then arg = """" & arg & """" argString = argString & " " & Arg Next scriptCommand = "cmd.exe /k " & engineFolder & "cscript.exe """ & WScript.ScriptFullName & """" & argString Shell.Run scriptCommand, , False WScript.Quit Else Exit Sub End IfEnd Subsetpagefile.vbs.txt Link to comment Share on other sites More sharing options...
FlierMate Posted November 13, 2011 Share Posted November 13, 2011 Description: My own compression technology identical to RLE (Run-Length Encoding) using frequency table with low compression ratio.Title:Squeeze-Together(im) Compression TechnologyResearched and Developed by Boo Khan MingPurpose:Compress all types of file regardless of file size.Functions:function SqueezeFile(InputFileName,OutputFileName:string):byte;function StretchFile(InputFileName,OutputFileName:string):byte;Programming Language: Turbo Pascalcompress.zip Link to comment Share on other sites More sharing options...
FlierMate Posted November 13, 2011 Share Posted November 13, 2011 (edited) Description: Converts plain text file to self-displaying .COM program.There are similar converters out there, but I reinvent the wheel.Note: Make sure your text file does not contain the dollar sign. (As "$" is reserved as the terminator string)How It Works: The equivalent assembly instruction code is as follows: (0eh in length) push cs pop ds mov dx, 014b ;this is the offset in current COM image block (100h) mov ah, 09 int 21 mov ax, 4c00 ;zero exit code int 21 . <Compiler ID> (3ah in length) . <String segment starts here> . . <Terminator string - $>Programming Language: Turbo Pascal and/or Assembly Languagetxt2coms.zip Edited November 13, 2011 by FlierMate Link to comment Share on other sites More sharing options...
FlierMate Posted November 13, 2011 Share Posted November 13, 2011 Description: Wait For a Mouse Event (Useful for Your Batch Programming)Screenshot: Please follow step-by-step as the screenshot shown below:Note:DEBUG is a native DOS command.You will notice new CLICK.COM file in the directory.After you run this tiny program, you have to click using your left mouse button on any part of the screen in order to continue (or return to command prompt)Programming Language: Assembly Language Link to comment Share on other sites More sharing options...
dencorso Posted April 5, 2014 Share Posted April 5, 2014 Purpose: to delete all $RECYCLE.BIN (aka Recycle Bin.BIN) folders across all fixed partitions in a machine.Language: batch scriptIntroduction: Multibooting on machines using mainly FAT filesystems can lead to the Recycle Bin.BIN issue... This is a clean-up script aiming at removing those annoying extra folders, across all the partitions marked as non-removable in a given machine.Requirements: unix classic colrm.exe (findable inside util-linux-ng-2.14.1-bin.zip) and Uwe Sieber's ListDOSDevices.exe (findable here).I call it DelBinBin.cmd and it's pretty simple, although I bet it can be made still simpler:@echo offfor /F "tokens=*" %%1 in ('listdosdevices ^| find /i "fixed" ^| colrm 3') do RD /S /Q "%%1\$Recycle.BIN" 2> nulLater addition:Yzöwl has devised an interesting alternative option for achieving the same result from XP or later, without requiring the use of any 3rd party tools:@For /f "tokens=2 delims==:" %%# In ( 'Wmic LogicalDisk Where "DriveType=3" Get DeviceID /value' ) do @RD/s/q %%#:\$Recycle.BINThanks a lot, Yzöwl. You do rock! Link to comment Share on other sites More sharing options...
shorterxp Posted June 17, 2018 Share Posted June 17, 2018 I can't seem to post in the Code section fo forum is this normal? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now