Monday, 13 May 2019

ClearClipboard.exe clears any data on the Windows' clipboard

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 ClearClipboard.bat
REM This file compiles ClearClipboard.vb to ClearClipboard.exe using the system VB.NET compiler
REM ClearClipboard clears any data on the Windows' clipboard
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:winexe /out:"%~dp0\ClearClipboard.exe" "%~dp0\ClearClipboard.vb" 
pause



'ClearClipboard.vb
Imports System
Imports System.Windows.Forms.Clipboard
Public Module MyApplication  


 Sub Main()
  System.Windows.Forms.Clipboard.Clear()
 End Sub
End Module

Sunday, 12 May 2019

ListAttr.exe lists all 19 of the attributes of a file, folder, volume, or device.

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.
@echo off
ECHO Three files follow
ECHO ListAttr.bat
ECHO This file compiles ListAttr.vb to ListAttr.exe using the system VB.NET compiler.
ECHO ListAttr.exe lists all 19 of the attributes of a file, folder, volume, or device.
Echo To Use
Echo         ListAttr ^
Echo -----------------------------------------------------------------------------------------
C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc "%~dp0\ListAttr.vb" /out:"%~dp0\ListAttr.exe" /target:exe
Pause



Echo ListAttrTest.Bat
"%~dp0\ListAttr" C:
"%~dp0\ListAttr" C:\
"%~dp0\ListAttr" C:\Windows\System32\Catroot
"%~dp0\ListAttr" nul
"%~dp0\ListAttr" c:\bootnxt
For /d %%A in ("C:\Windows\*") Do @"%~dp0\ListAttr" %%~A
Pause



'ListAttr.vb
imports System.Runtime.InteropServices 
Public Module MyApplication  

Public Declare Unicode Function GetFileAttributesW Lib "Kernel32" (ByVal Path As String) As Integer
Public Const FILE_ATTRIBUTE_ARCHIVE = 32 
Public Const FILE_ATTRIBUTE_COMPRESSED = 2048 
Public Const FILE_ATTRIBUTE_DEVICE = 64 
Public Const FILE_ATTRIBUTE_DIRECTORY = 16 
Public Const FILE_ATTRIBUTE_ENCRYPTED = 16384 
Public Const FILE_ATTRIBUTE_HIDDEN = 2 
Public Const FILE_ATTRIBUTE_INTEGRITY_STREAM = 32768 
Public Const FILE_ATTRIBUTE_NORMAL = 128 
Public Const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 8192 
Public Const FILE_ATTRIBUTE_NO_SCRUB_DATA = 131072 
Public Const FILE_ATTRIBUTE_OFFLINE = 4096 
Public Const FILE_ATTRIBUTE_READONLY = 1 
Public Const FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = 4194304 
Public Const FILE_ATTRIBUTE_RECALL_ON_OPEN = 262144 
Public Const FILE_ATTRIBUTE_REPARSE_POINT = 1024 
Public Const FILE_ATTRIBUTE_SPARSE_FILE = 512 
Public Const FILE_ATTRIBUTE_SYSTEM = 4 
Public Const FILE_ATTRIBUTE_TEMPORARY = 256 
Public Const FILE_ATTRIBUTE_VIRTUAL = 65536 
  
Public Sub Main ()
 Dim Ret as Integer
 Dim OutPut As String
 Output = Command() & " - " & vbtab & vbtab
 Ret = GetFileAttributesW(Command())
 If Ret = -1 Then 
  Console.writeline("Error " & err.lastdllerror)
 Else
  If (Ret And FILE_ATTRIBUTE_ARCHIVE) = FILE_ATTRIBUTE_ARCHIVE Then Output = OutPut & "Archive "
  If (Ret And FILE_ATTRIBUTE_COMPRESSED) = FILE_ATTRIBUTE_COMPRESSED Then Output = OutPut & "Compressed "
  If (Ret And FILE_ATTRIBUTE_DEVICE) = FILE_ATTRIBUTE_DEVICE Then Output = OutPut & "Device "
  If (Ret And FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY Then Output = OutPut & "Directory "
  If (Ret And FILE_ATTRIBUTE_ENCRYPTED) = FILE_ATTRIBUTE_ENCRYPTED Then Output = OutPut & "Encrypted "
  If (Ret And FILE_ATTRIBUTE_HIDDEN) = FILE_ATTRIBUTE_HIDDEN Then Output = OutPut & "Hidden "
  If (Ret And FILE_ATTRIBUTE_INTEGRITY_STREAM) = FILE_ATTRIBUTE_INTEGRITY_STREAM Then Output = OutPut & "Integrity_Stream "
  If (Ret And FILE_ATTRIBUTE_NORMAL) = FILE_ATTRIBUTE_NORMAL Then Output = OutPut & "Normal "
  If (Ret And FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) = FILE_ATTRIBUTE_NOT_CONTENT_INDEXED Then Output = OutPut & "Not_Content_Indexed "
  If (Ret And FILE_ATTRIBUTE_NO_SCRUB_DATA) = FILE_ATTRIBUTE_NO_SCRUB_DATA Then Output = OutPut & "No_Scrub_Data "
  If (Ret And FILE_ATTRIBUTE_READONLY) = FILE_ATTRIBUTE_READONLY Then Output = OutPut & "ReadOnly "
  If (Ret And FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS) = FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS Then Output = OutPut & "Recall_On_Data_Access "
  If (Ret And FILE_ATTRIBUTE_RECALL_ON_OPEN) = FILE_ATTRIBUTE_RECALL_ON_OPEN Then Output = OutPut & "Recall_On_Open "
  If (Ret And FILE_ATTRIBUTE_REPARSE_POINT) = FILE_ATTRIBUTE_REPARSE_POINT Then Output = OutPut & "Reparse "
  If (Ret And FILE_ATTRIBUTE_SPARSE_FILE) = FILE_ATTRIBUTE_SPARSE_FILE Then Output = OutPut & "Sparse "
  If (Ret And FILE_ATTRIBUTE_SYSTEM) = FILE_ATTRIBUTE_SYSTEM Then Output = OutPut & "System "
  If (Ret And FILE_ATTRIBUTE_TEMPORARY) = FILE_ATTRIBUTE_TEMPORARY Then Output = OutPut & "Temporary "
  If (Ret And FILE_ATTRIBUTE_VIRTUAL) = FILE_ATTRIBUTE_VIRTUAL Then Output = OutPut & "Virtual "
 End If
 Console.writeline(OutPut)
End Sub
End Module 

Saturday, 11 May 2019

SetWindowText.exe sets the titlebar text for a window

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.
Window Manipulation Posts

@Echo Off
Echo Two files follow
Echo SetWindowText.bat
Echo This file compiles SetWindowText.vb to SetWindowText.exe using the system VB.NET compiler.
Echo SetWindowText.exe sets the titlebar text for a window
Echo     SetWindowText.exe "OldWindowTitle" "NewWindowTitle"
Echo EG Open notepad and type in a command prompt
Echo     SetWindowText.exe "Untitled - Notepad" "My Window Title"
Echo ----------------------------------------------------------------------
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:winexe /out:"%~dp0\SetWindowText.exe" "%~dp0\SetWindowText.vb" 
pause



Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

Public Module MyApplication  


Public Declare UNICODE Function FindWindowW Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

Public Declare UNICODE Function SetWindowTextW Lib "user32" (ByVal hwnd As IntPtr, ByVal lpString As String) As Integer

Sub Main()
On Error Resume Next
Dim CmdLine As String
Dim Ret as Integer
Dim A() as String
Dim hwindows as IntPtr

CmdLine = Command()
If Left(CmdLine, 2) = "/?" Then
    MsgBox("Usage:" & vbCrLf & vbCrLf & "SetText ""OldWindowTitle"" ""NewWindowTitle""")
Else
    A = Split(CmdLine, Chr(34), -1, vbBinaryCompare)
    hwindows = FindWindowW(vbNullString, A(1))
    Ret = SetWindowTextW(hwindows, A(3))
End If
End Sub
End Module


Friday, 10 May 2019

TopMost.exe set a window on top or not

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.
Window Manipulation Posts

@Echo Off
Echo TopMost.bat
Echo This file compiles TopMost.vb to TopMost.exe
Echo TopMost.exe set a window on top or not
Echo To use 
Echo     TopMost Top ^
Echo     TopMost Not ^
Echo E.G.
Echo     TopMost Top Untitled - Notepad
Echo -----------------------------------------------------
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:winexe /out:"%~dp0\TopMost.exe" "%~dp0\TopMost.vb" 
pause



'TopMost.vb
Imports System
Imports System.IO
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

Public Module TopMost
 Public Declare UNICODE Function FindWindowW Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
 Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As IntPtr, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
 Public Const HWND_TOPMOST = -1
 Public Const SWP_NOMOVE = &H2
 Public Const SWP_NOSIZE = &H1
 Public Const HWND_NOTOPMOST = -2


 Sub Main()
  On Error Resume Next
  Dim hWindows as IntPtr
  Dim CmdLine as String
  Dim Ret as Integer
  CmdLine = Mid(Command(),5)
  hwindows = FindWindowW(vbNullString, CmdLine)
  If hwindows = 0 then
   Msgbox(Cmdline & " cannot be found.")
  Else
   If LCase(Left(Command(), 3)) = LCase("Top") then
    Ret = SetWindowPos(hwindows, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE)
    If Ret = 0 Then MsgBox("Set Pos Error is " & Err.LastDllError)
   ElseIf LCase(Left(Command(), 3)) = LCase("Not") then
    Ret = SetWindowPos(hwindows, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE)
    If Ret = 0 Then MsgBox("Set Pos Error is " & Err.LastDllError)
   Else
    Msgbox("Command line not recognised")
   End If
  End If
 End Sub
End Module

Thursday, 9 May 2019

DeDup.exe Removes duplicate lines from StdIn and writes to StdOut

REM DeDup.bat
REM This file compiles DeDup.vb to DeDup.exe
REM DeDup.exe Removes duplicate lines from StdIn and writes to StdOut
REM To use
REM DeDup  < inputfile.txt > outputfile.txt
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:exe /out:"%~dp0\DeDup.exe" "%~dp0\DeDup.vb" /verbose
pause










'DeDup.vb
Imports System
Imports System.IO
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

Public Module DeDup
Sub Main
        Dim Dict as Object
        Dict = CreateObject("Scripting.Dictionary")
        Dim Line As Object
        Line=Console.readline
        Do Until Line = vbnull
                On Error Resume Next
                Dict.Add(Line, "")
                On Error Goto 0
                Line=Console.readline
        Loop


        For Each thing in Dict.Keys()
                Console.writeline(thing)
        Next
End Sub
End Module