Last active
June 4, 2023 03:54
-
-
Save bryanjhv/b2b74ac0fd9fa3e8a321363a70ec47ea to your computer and use it in GitHub Desktop.
Find SAP installation in ActiveDirectory using WScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function(WSH) { | |
function trim(msg) { | |
return msg.replace(/\s+/g, '') | |
} | |
function log(tag, msg) { | |
WSH.StdOut.WriteLine(`[${tag}] ${msg}`) | |
} | |
function fail(msg) { | |
log('E', msg) | |
WSH.Quit(1) | |
} | |
// Read host | |
let host = null | |
const args = WSH.Arguments | |
if (args.Length > 0) host = trim(args(0)) | |
if (!host) { | |
log('I', 'reading host') | |
WSH.StdOut.Write('HOST: ') | |
host = trim(WSH.StdIn.ReadLine()) | |
if (!host) return fail('missing host') | |
} | |
log('I', `host ${host} set`) | |
// Ping host | |
log('I', `ping to ${host}`) | |
const shl = WSH.CreateObject('WScript.Shell') | |
const offline = shl.Run(`ping -n 1 ${host}`, 0, true) | |
if (offline) return fail('host is offline') | |
// Find SAP folder | |
const app = WScript.CreateObject('Shell.Application') | |
const fso = WScript.CreateObject('Scripting.FileSystemObject') | |
let path = `\\\\${host}\\c$\\Program Files (x86)\\SAP\\FrontEnd\\SAPGui` | |
log('I', 'reading SAP 64') | |
if (!fso.FolderExists(path)) { | |
log('I', 'reading SAP 32') | |
path = path.replace(' (x86)', '') | |
if (!fso.FolderExists(path)) return fail('no SAP found') | |
} | |
// Get SAP version | |
const folder = app.NameSpace(path) | |
const item = folder.ParseName('SAPgui.exe') | |
log('S', `SAP ${folder.GetDetailsOf(item, 271)}`) | |
// Look for TBarCode | |
path = `\\\\${host}\\c$\\ProgramData\\TEC-IT\\TBarCode SAPwin\\10` | |
log('I', 'reading TBarCode') | |
if (!fso.FolderExists(path)) return fail('no tbar found') | |
log('S', 'TBarCode was found') | |
})(WScript) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment