Category: Scripting

Run PowerShell script bypassing execution policy
article #1131, updated 2525 days ago

Run it like this, from CMD:

"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass script.ps1

Categories:      

==============

AutoHotKey and VBscript self-elevate to administrator
article #1104, updated 2603 days ago

There is a way:

https://autohotkey.com/docs/commands/Run.htm#RunAs

http://www.kellestine.com/self-elevate-vbscript/

Categories:      

==============

Script/Macro capability won't enable in VBA
article #934, updated 3167 days ago

If all of your settings are correct but you still get the popup saying that macros are disabled, your OTM file — the VBA project file — is corrupt. In the case of Outlook:

  1. Export your modules to .BAS files
  2. Exit Outlook
  3. Go here in Explorer:
    C:\Users\[user]AppData\Roaming\Microsoft\Outlook
  4. Delete the OTM file
  5. Restart Outlook
  6. Import your exported .BAS files into the new VBA project which it created for you.

Categories:      

==============

Great VBScript reference
article #928, updated 3172 days ago

Seems like certain VBScript references are being ripped off of the Web; thus it was great to see this:

http://ss64.com/vb

Categories:      

==============

Windows automation / keyboard and mouse macros, in Python
article #823, updated 3447 days ago

Two very interesting and related developments:

https://code.google.com/p/pywinauto/

https://code.google.com/p/swapy/

Categories:      

==============

WordPerfect Files
article #737, updated 3706 days ago

It’s not very much documented, but if you have a lot of WordPerfect files, try renaming their extensions to .DOC. Word will load them, unless they are very old files from WordPerfect for DOS.

If you have a huge tree of WPD files, use a batch file like this:

For /R "X:\TOP_OF_TREE" %%G in (.) Do (
 Pushd %%G
 Echo now in %%G
 ren *.wpd *.doc
 Popd )
Echo "Done!"

Categories:      

==============

An excellent resource on CMD, VBscript, PowerShell, Bash, Oracle, OS X, SQL Server, Access...
article #628, updated 3958 days ago

Try this:

http://ss64.com

Categories:      

==============

Detect Computer Group Membership
article #544, updated 4203 days ago

Try this:

Dim objNetwork
Set objNetwork = CreateObject("WScript.Network")

Dim objWinntComp
Set objWinntComp = GetObject("WinNT://" & objNetwork.UserDomain & "/" & objNetwork.ComputerName & ",computer")
MsgBox "WinNT://" & objNetwork.UserDomain & "/" & objNetwork.ComputerName & ",computer"

Dim strGroupToCheck
strGroupToCheck = "GROUP_TO_DETECT"

If IsMemberOfGroup(objNetwork.UserDomain, objWinntComp, strGroupToCheck) = True Then
      MsgBox "You are a member of " & strGroupToCheck
ElseIf IsMemberOfGroup(objNetwork.UserDomain, objWinntComp, strGroupToCheck) = False Then
      MsgBox "You are NOT a member of " & strGroupToCheck
      WScript.Quit
ElseIf IsMemberOfGroup(objNetwork.UserDomain, objWinntComp, strGroupToCheck) = "Error" Then
      MsgBox "There was no group found called " & strGroupToCheck
      WScript.Quit
End If      

Function IsMemberOfGroup(strUserDomain, objComp, strGroup) 'the user is a member of a specified group
      IsMemberOfGroup = False
      Dim objGroup
      On Error Resume Next
      Set objGroup = GetObject("WinNT://" & strUserDomain & "/" & strGroup & ",group")
      If Err.Number Then
            IsMemberOfGroup = "Error"
      Else
            IsMemberOfGroup = objGroup.IsMember(objComp.ADsPath & "$")
      End If
End Function

Categories:      

==============

Iterate a folder in CMD
article #519, updated 4258 days ago

Try this:

@echo off
for /D %%Q in (C:\*) do echo Directory:  %%Q
for %%Q in (C:\*) do echo File:  %%Q

The above is a solid batch file — if you use the logic in the command shell, use single percents, not doubles!

Categories:      

==============

Choose one or more files in Access (or other VBA) 2010
article #412, updated 4630 days ago

The below is revised from here. It works well, as long as a reference to the Microsoft Office [currentversion] Type Library is created. This is confirmed to work well in Access 2010.

Public Function ChooseFile() As String

    With Application.FileDialog(msoFileDialogFilePicker) 
        .AllowMultiSelect = False 'Select only one file
        .Title = "Choose file" 'Set dialog title
        .ButtonName = "Choose" 'Set the button caption
        '.Filters.Clear 'Make sure the filter list is clear
        'Add 2 filters
            '.Filters.Add "JPEGs", "*.jpg"
            '.Filters.Add "Bitmaps", "*.bmp"
            '.FilterIndex = 2 ' Set the filter index to 2
            '.Filters.Add "All", "*.*"

        'Set initial path
        .InitialFileName = "" 

        'Optionally show files as thumbnails
        '.InitialView = msoFileDialogViewThumbnail
        .InitialView = msoFileDialogViewList

        'Show the dialog and test the return
        If .Show = 0 Then
            'didn't pick a file - exit sub
            ChooseFile = ""
            Exit Function
        End If

        'Should be only one file name - grab it
        ChooseFile = Trim(.SelectedItems(1))  

        'On Error Resume Next 'Set error trap

    End With

End Function

Categories: