VBscript fails to pin items to taskbar on Windows Insider build - powershell

I have a script that will pin an item to the taskbar in all OS's except the Windows Insider builds. I converted it to a Powershell script and it also works on all OS's except the Windows Insider build. When I run it, I don't get any error messages, nothing in the Event Viewer. MS has been locking down the ability to programmatically pin items to both the Start Menu and the Taskbar. It looks like they're going further in upcoming releases. Has anyone else run into this? Here is the code I'm using.
Function PinItem(strFolder, strFile)
Dim ShortcutPath
Dim sKey1
Dim sKey2
Dim KeyValue
'----------------------------------------------------------------------
Set objFSO = CreateObject("Scripting.FileSystemObject")
ShortcutPath = strFolder & "\" & strFile
sKey1 = "HKCU\Software\Classes\*\shell\{:}\\"
sKey2 = Replace(sKey1, "\\", "\ExplorerCommandHandler")
'----------------------------------------------------------------------
With WScript.CreateObject("WScript.Shell")
KeyValue = .RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer" & _
"\CommandStore\shell\Windows.taskbarpin\ExplorerCommandHandler")
.RegWrite sKey2, KeyValue, "REG_SZ"
With WScript.CreateObject("Shell.Application")
With .Namespace(objFSO.GetParentFolderName(ShortcutPath))
With .ParseName(objFSO.GetFileName(ShortcutPath))
.InvokeVerb("{:}")
End With
End With
End With
.Run("Reg.exe delete """ & Replace(sKey1, "\\", "") & """ /F"), 0, True
End With
End Function

Related

Scripted Export of Enterprise Architect Model

I am working on a model which is stored in a Postgresql Database. There exists a eapx file, to access this model.
Is it possible to write a script, to automatically export the Model to XML Files or similar, to create a regular snapshot?
You can use the EA.Project.ProjectTransfer() to export model to an eap(x) file.
Here's an example vbs script that can be executed by double-clicking it in the the windows explorer.
option explicit
' Purpose: Automated Project Transfer from DBMS to EAP file as weekly backup. See end of script for different databases that are backed up.
const logPath = "C:\shares\Backups\LogFile\"
const backupPath = "C:\shares\Backups\"
sub main
EADEV
MsgBox ("Back-up Finished.")
end sub
sub EADEV
Dim CurrentDate
Currentdate = (Year(Date) & (Right(String(2,"0") & Month(Date), 2)) & (Right(String(2,"0") & Day(Date), 2))) 'yyyymmdd'
dim repository
dim projectInterface
set repository = CreateObject("EA.Repository")
Dim FileName
Filename = "EA_Export.eap"
dim LogFilePath
LogFilePath = logPath&CurrentDate & " EA DEV (back-up).log"
dim TargetFilePath
TargetFilePath = logPath & "EA_Export.eap"
dim eapString
eapString = "DBType=1;Connect=Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DB_Name;Data Source=ServerName;LazyLoad=1;"
'get project interface
set projectInterface = repository.GetProjectInterface()
projectInterface.ProjectTransfer eapString, TargetFilePath, LogFilePath
'close EA
repository.Exit
Dim newFilename
newFilename = backupPath & CurrentDate & " EA DEV (back-up).eap"
Dim Fso
Set Fso = WScript.CreateObject("Scripting.FileSystemObject")
Fso.MoveFile TargetFilePath, newFileName
end sub
main
In order to know what to put in the eapString you can connect to your database project and then save as a shortcut.
Then open the resulting file in a text editor and you'll find the connection string you need.

Scan a subnet for an application that is NOT installed

I have been trying to come up with a script that will scan a specific subnet for an application not having been installed yet. I need to see if Lync is installed on some remote subnets before we turn up the sites live next month.
I have been running this as a logon script but it doesn't tell me what subnet they are in and it's not populating fast enough as users don't logoff.
On Error Resume Next
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = WScript.CreateObject("WScript.Network")
strValue = objShell.RegRead("HKCU\Software\MRC Custom\Skype_Audit")
If strValue <> "Gathered 1.0" Then
objShell.RegWrite "HKCU\Software\MRC Custom\Skype_Audit", "Gathered 1.0"
x86 = objShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%")
skypePath = x86 & "\Microsoft Office\Office15\lync.exe"
If objFSO.FileExists(skypePath) Then
version = objFSO.GetFileVersion(skypePath)
Else
version = "not installed"
End If
'Bind to the users DN
strUserPath = "LDAP://" & objSysInfo.UserName
set objUser = GetObject(strUserPath)
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'Write Data to Log File
Const ForAppending = 8
strPath = "\\mcjunkinredman\data\userpub\Skype_Audit\Log.txt"
Set objTextFile = objFSO.OpenTextFile(strPath, ForAppending, True)
objTextFile.WriteLine objUser.samAccountName & "|" & objNetwork.ComputerName & "|" & version
End If
VBScript or PowerShell is fine, any help would be appreciated.
I wrote an article a while back that provides a script that connects to remote computers and retrieves the applications that are installed:
Windows IT Pro: Auditing 32-Bit and 64-Bit Applications with PowerShell

vbscript with outdated MS Access and Outlook

I have a VBscript that I wrote for someone that access their Microsoft Access Database and sends an email, via Outlook, to people in the database if they fit a certain criteria. I have the script run every day via Task Manager. The important part of the script is to run completely in the background
I developed this script on Windows 7 with the 2013 version of Access and Outlook, but when I went to set up the code on the person's computer, they had an out-dated version of Microsoft Office (I'm pretty sure it's 2010 or 2007, but I'm not familiar with any Office products earlier than 2013). Everything worked fine on Windows 7 with Office 2013
When I ran the script I came across two errors:
Outlook prompted the user saying that a script is trying to automatically send an email and to allow it to do so.
The email wasn't went strait to the outbox and wouldn't send (although I'm pretty sure that's because I didn't set up the Outlook account right)
How can I fix this?
Here is the code:
Dim connStr, objConn, getNames
connStr = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\source\to\database.accdb"
Set objConn = CreateObject("ADODB.Connection")
objConn.open connStr
Set rs = objConn.execute("SELECT Fname, Email, VolunteerDate, ID, VolunteerTime FROM people")
DO WHILE NOT rs.EOF
getNames = getNames + rs.Fields(1) & ","
Dim diff
diff = DateDiff("d",Date,rs.Fields(2))
Select Case diff
Case 0
Call sendTodayEmail(rs.Fields(1),rs.Fields(2),rs.Fields(0), rs.Fields(4))
Case 7
Call sendWeekEmail(rs.Fields(1),rs.Fields(2),rs.Fields(0), rs.Fields(4))
Case else
End Select
rs.MoveNext
Loop
Sub sendTodayEmail(a,b,c,d)
dim objOutlk
dim objMail
dim strMsg
const olMailItem = 0
set objOutlk = createobject("Outlook.Application")
set objMail = objOutlk.createitem(olMailItem)
objMail.To = a
objMail.subject = "Automatic Email"
strMsg = "Hello " & c & ", this is a reminder that you are scheduled to help today at " & d
objMail.body = strMsg
objMail.Send
End Sub
Sub sendWeekEmail(a,b,c,d)
dim objOutlk
dim objMail
dim strMsg
const olMailItem = 0
set objOutlk = createobject("Outlook.Application")
set objMail = objOutlk.createitem(olMailItem)
objMail.To = a
objMail.subject = "Automatic Email"
strMsg = "Hello " & c & ", this is a reminder that you are scheduled to help one week from today at " & d & "." & vbCrLf & "Scheduled date: " & b & vbCrLf & "Scheduled time: " & d
objMail.body = strMsg
objMail.Send
End Sub
Set objConn = Nothing
Newer versions of Outlook will not display security prompts if an up-to-date version of an anti-virus app is installed.
Otherwise your options are either Extended MAPI (C++ or Delphi only), Redemption (any language - I am its author) or products like ClickYes.
See http://www.outlookcode.com/article.aspx?id=52 for more details.

Use VBScript in HTML to write a PowerShell script

I'm trying to use VBScript in HTML to write text into what will become a powershell script. I am doing this to avoid having to statically code into my HTA the location of these powershell scripts.
My problem becomes working around Powershell's " ( and )
An example, I'm just not sure how to wrap the characters in order to keep VBS happy.
Dim filesys, filetxt
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile("c:\Temp\somefile.txt", ForAppending, True)
filetxt.WriteLine ("Param([Parameter(Mandatory=$true)]")
filetxt.WriteLine ("[string]$Str)")
filetxt.WriteLine ("# Create the IE com object")
filetxt.WriteLine ("$ie = new-object -comobject InternetExplorer.Application")
filetxt.WriteLine ("#Navigate to www.")
filetxt.WriteLine ("$ie.navigate("http://www.page.com")")
Assuming that last line is your only issue, you can escape the quotes either by doubling them up or by using Chr(34) to programatically insert them.
filetxt.WriteLine ("$ie.navigate(""http://www.page.com"")")
filetxt.WriteLine ("$ie.navigate(" & Chr(34) & "http://www.page.com" & Chr(34) & ")")

Excel will not close processes

So, I'm using (after modification) this code, from here: How to set recurring schedule for xlsm file using Windows Task Scheduler
My error: Runtime error: Unknown runtime error.
I've searched far and wide to find an way to close the Excel process, but almost everybody uses .Quit sadly it gives the above error. I've also tried .Close, but that is not recognized
' Create a WshShell to get the current directory
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
' Create an Excel instance
Dim myExcelWorker
Set myExcelWorker = CreateObject("Excel.Application")
' Disable Excel UI elements
myExcelWorker.DisplayAlerts = False
myExcelWorker.AskToUpdateLinks = False
myExcelWorker.AlertBeforeOverwriting = False
myExcelWorker.FeatureInstall = msoFeatureInstallNone
' Tell Excel what the current working directory is
Dim strSaveDefaultPath
Dim strPath
strSaveDefaultPath = myExcelWorker.DefaultFilePath
strPath = "C:\Users\hviid00m\Desktop"
myExcelWorker.DefaultFilePath = strPath
' Open the Workbook specified on the command-line
Dim oWorkBook
Dim strWorkerWB
strWorkerWB = strPath & "\Status Report (Boxplots) TEST.xlsm"
Set oWorkBook = myExcelWorker.Workbooks.Open (strWorkerWB, , , , , , True)
' Build the macro name with the full path to the workbook
Dim strMacroName
strMacroName = "Refresh"
on error resume next
myExcelWorker.Run strMacroName
if err.number <> 0 Then
WScript.Echo "Fejl i macro"
End If
err.clear
on error goto 0
oWorkBook.Save
' Clean up and shut down
' Don’t Quit() Excel if there are other Excel instances
' running, Quit() will shut those down also
myExcelWorker.Quit <--- ERROR
Set oWorkBook = Nothing
Set myExcelWorker = Nothing
Set WshShell = Nothing
Found some code on a different side.
The reason why (as far as I understood) is that .Quit and .Close is for VBA not VBS.
' Clean up and shut down
' Don’t Quit() Excel if there are other Excel instances
' running, Quit() will shut those down also
Dim objWMIService, objProcess, colProcess
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & "'EXCEL.EXE'")
For Each objProcess in colProcess
objProcess.Terminate()
Next`
Set oWorkBook = Nothing
Set myExcelWorker = Nothing
Set WshShell = Nothing