Tuesday, 3 December 2019

Speaking Clock in VBScript.


'One file follows
'SpeakingClock.vbs
'Speaks the time continuously
Set speech = CreateObject("sapi.spvoice")
Do
If Hour(Now) < 12 then
Var = Hour(Now) & " AM"
else
Var = Hour(Now) - 12 & " PM"
End If

speech.Speak Var & " and " & Minute(Now) & " minutes and " & Second(Now) & " seconds"
wscript.sleep 5
Loop

Monday, 2 December 2019

RunAsAdminConsole.exe eleates a existing console or runs a command leaving the console elevated. The program prompts for credentials.

This uses the inbuilt compilers in Windows 10 - there are three VB.NET compilers and three C# compilers - just copy each text file into the same folder and double click the batch file to make the program.
REM Three files follow
REM RunAsAdminConsole.bat
REM This file compiles RunAsAdminconsole.vb to RunAsAdminconsole.exe using the system VB.NET compiler.
REM Runs a command elevated using a manifest OR elevates the current console without parameters.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc "%~dp0\RunAsAdminconsole.vb" /win32manifest:"%~dp0\RunAsAdmin.manifest" /out:"%~dp0\RunAsAdminConsole.exe" /target:exe
REM To use
rem RunAsAdminconsole 
pause



;RunAsAdminConsole.vb
imports System.Runtime.InteropServices 
Public Module MyApplication  
  
 Public Sub Main ()
  Dim wshshell as object
  WshShell = CreateObject("WScript.Shell")
  Shell("cmd /k " & Command())
 End Sub 

End Module 


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
    version="1.0.0.0"
    processorArchitecture="*"
    name="Color Management"
    type="win32"
/>
<description>Serenity's Editor</description>
<trustinfo xmlns="urn:schemas-microsoft-com:asm.v2"> 
<security> 
    <requestedprivileges> 
        <requestedexecutionlevel level="requireAdministrator" uiAccess="false"/> 
    </requestedPrivileges> 
</security> 
</trustInfo> 

</assembly>

Thursday, 28 November 2019

RunAsAdmin - Run a program elevated. The program prompts for credentials.

This uses the inbuilt compilers in Windows 10 - there are three VB.NET compilers and three C# compilers - just copy each text file into the same folder and double click the batch file to make the program.
REM Three files follow
REM RunAsAdminConsole.bat
REM This file compiles RunAsAdmin.vb to RunAsAdmin.exe using the system VB.NET compiler.
REM Runs a program elevated using a manifest
C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc "%~dp0\RunAsAdmin.vb" /win32manifest:"%~dp0\RunAsAdmin.manifest" /out:"%~dp0\RunAsAdmin.exe" /target:winexe
REM To use
REM     RunAsAdmin 
pause



'RunAsAdmin.vb
imports System.Runtime.InteropServices 
Public Module MyApplication  
 Public Sub Main ()
  Dim wshshell as object
  WshShell = CreateObject("WScript.Shell")
  WshShell.Run(Command())
 End Sub 
End Module 




RunAsAdmin.Manifest
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="Color Management" type="win32" /> <description>Serenity's Editor</description> <trustinfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedprivileges> <requestedexecutionlevel level="requireAdministrator" uiAccess="false"/> </requestedPrivileges> </security> </trustInfo> </assembly>

Tuesday, 11 June 2019

ChangeWallpaper.exe - Changes the desktop wallpaper from the command line

This uses the inbuilt compilers in Windows 10 - there are three VB.NET compilers and three C# compilers - just copy each text file into the same folder and double click the batch file to make the program.

Although this is from the 2001 documentation and has been removed from current.


Setting pvParam to "" removes the wallpaper. Setting pvParam to VBNULL reverts to the default wallpaper.

See docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfow

REM Compiles ChangeWallpaper.vb to ChangeWallpaper.exe
REM To use
REM ChangeWallpaper Wallpaper.bmp
REM EG ChangeWallpaper "C:\Windows\Web\Wallpaper\Theme1\img1.jpg"
C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc "ChangeWallpaper.vb" /out:"%~dp0\ChangeWallpaper.exe" /target:winexe
pause



;ChangeWallpaper.vb
Imports System.Runtime.InteropServices
Imports System.Windows.Forms

Public Module SendWinKey
    Public Declare Unicode Function SystemParametersInfoW Lib "user32" (ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As String, ByVal fuWinIni As Integer) As Integer
    Public Const SPI_SETDESKWALLPAPER = 20
    Public Const SPIF_SENDWININICHANGE = &H2
    Public Const SPIF_UPDATEINIFILE = &H1

Public Sub Main()    
    Dim Ret as Integer
    Dim FName As String
    'Takes a filename on the command line removing quotes
    FName = Replace(Command(), """", "")
    Ret = SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, FName, SPIF_SENDWININICHANGE + SPIF_UPDATEINIFILE)
    If Ret = 0 Then Msgbox(err.lastdllerror)
End Sub

End Module

Friday, 7 June 2019

Simulates the PrintScreen Key - SendKeys implemented in Windows Scripting and Basic languages cannot send PrintScreen key, this program allows the PrintScreen key to be simulated.

This uses the inbuilt compilers in Windows 10 - there are three VB.NET compilers and three C# compilers - just copy each text file into the same folder and double click the batch file to make the program.
REM Compiles PrintScreen.vb to PrintScreen.exe
REM SendKeys implemented in Windows Scripting and Basic languages cannot send PrintScreen key, this program allows the PrintScreen key to be simulated.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc "%~dp0\PrintScreen.vb" /out:"%~dp0\PrintScreen.exe" /target:winexe
pause





Imports System.Runtime.InteropServices
Imports System.Windows.Forms

Public Module SendWinKey
    Const KEYEVENTF_KEYDOWN As Integer = &H0
    Const KEYEVENTF_KEYUP As Integer = &H2

    Declare Sub keybd_event Lib "User32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As UInteger, ByVal dwExtraInfo As UInteger)

Public Sub Main()    
        keybd_event(CByte(Keys.PrintScreen), 0, KEYEVENTF_KEYDOWN, 0) 'press the PrintScreen key down
        keybd_event(CByte(Keys.PrintScreen), 0, KEYEVENTF_KEYUP, 0) 'release the PrintScreen key
End Sub

End Module