Jay Taylor's notes

back to listing index

batch.scripts/hybrids/jscript/shortcutJS.bat at master · npocmaka/batch.scripts · GitHub

[web search]
Original source (github.com)
Tags: programming windows icons batch-script shortcut.lnk github.com
Clipped on: 2024-11-26

Skip to content

Navigation Menu

Collapse file tree

Files

  • DateAndTime
  • Java
  • ProcessesUtils
  • dataStructures
  • discovers_and_bugs
  • fileUtils
  • hybrids
    • .net
    • iexpress
    • jscript
      • imageProcessing
      • FileTimeFilterJS.bat
      • ShellRunJS.bat
      • UIautoLogin.bat
      • WinHTTPDownloadJS.bat
      • XMLHTTPDownloadJS.bat
      • base64.bat
      • calcjs.bat
      • deleteJS.bat
      • dirTimesJS.bat
      • drivesInfoJS.bat
      • edit.json.bat
      • ejectjs.bat
      • enterNumberJS.bat
      • fileTImesJS.bat
      • focusOn.bat
      • freememjs.bat
      • getInnerText.bat
      • guid.bat
      • imgInfo.bat
      • jsonextractor.bat
      • jspopup.bat
      • julian.bat
      • listVerbs.bat
      • mediarunner.bat
      • oneDriveSync.bat
      • pdfPageCounter.bat
      • phisycalDrives.bat
      • pinnerJS.bat
      • ppt2pdf.bat
      • printJS.bat
      • replacer.bat
      • sendKeys.bat
      • shellCopy.bat
      • shortcutJS.bat
      • slowTypeJS.bat
      • splitjs.bat
      • spplayer.bat
      • toHexJS.bat
      • toHtmlEnt.bat
      • tooltipInfo.bat
      • unHexJS.bat
      • uuid.bat
      • winhttpjs.bat
      • write.bat
      • xpath.bat
      • xpath0.1.bat
      • yesnopopup.bat
      • zipjs.bat
    • makecab
    • mshta
    • wsh
  • math
  • network
  • other
  • printing
  • stringutils
  • system
  • LICENSE
  • README.md
/

shortcutJS.bat

Latest commit

8934c6c · Oct 26, 2016

History

History

File metadata and controls

216 lines (165 loc) · 5.88 KB
RawDownload raw file
You must be signed in to make or propose changes
Open symbols panel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
@if (@X)==(@Y) @end /* JScript comment
@echo off
cscript //E:JScript //nologo "%~f0" "%~nx0" %*
exit /b %errorlevel%
@if (@X)==(@Y) @end JScript comment */
var args=WScript.Arguments;
var scriptName=args.Item(0);
//var adminPermissions= false;
var edit= false;
function printHelp() {
WScript.Echo(scriptName + " -linkfile link -target target [-linkarguments linkarguments] "+
" [-description description] [-iconlocation iconlocation] [-hotkey hotkey] "+
" [-windowstyle 1|3|7] [-workingdirectory workingdirectory] [-adminpermissions yes|no]");
WScript.Echo();
WScript.Echo(scriptName + " -edit link [-target target] [-linkarguments linkarguments] "+
" [-description description] [-iconlocation iconlocation] [-hotkey hotkey] "+
" [-windowstyle 1|3|7] [-workingdirectory workingdirectory] [-adminpermissions yes|no]");
WScript.Echo();
WScript.Echo(scriptName + " -examine link");
WScript.Echo();
WScript.Echo(" More info: http://msdn.microsoft.com/en-us/library/xk6kst2k%28v=vs.84%29.aspx ");
}
// reads the given .lnk file as a char array
function getlnkChars(lnkPath) {
// :: http://www.dostips.com/forum/viewtopic.php?f=3&t=3855&start=15&p=28898 ::
var ado = WScript.CreateObject("ADODB.Stream");
ado.Type = 2; // adTypeText = 2
ado.CharSet = "iso-8859-1"; // code page with minimum adjustments for input
ado.Open();
ado.LoadFromFile(lnkPath);
var adjustment = "u20ACu0081u201Au0192u201Eu2026u2020u2021" +
"u02C6u2030u0160u2039u0152u008Du017Du008F" +
"u0090u2018u2019u201Cu201Du2022u2013u2014" +
"u02DCu2122u0161u203Au0153u009Du017Eu0178" ;
var fs = new ActiveXObject("Scripting.FileSystemObject");
var size = (fs.getFile(lnkPath)).size;
var lnkBytes = ado.ReadText(size);
ado.Close();
var lnkChars=lnkBytes.split('');
for (var indx=0;indx<size;indx++) {
if ( lnkChars[indx].charCodeAt(0) > 255 ) {
lnkChars[indx] = String.fromCharCode(128 + adjustment.indexOf(lnkChars[indx]));
}
}
return lnkChars;
}
function hasAdminPermissions(lnkPath) {
return (getlnkChars(lnkPath))[21].charCodeAt(0) == 32 ;
}
function setAdminPermissions(lnkPath , flag) {
lnkChars=getlnkChars(lnkPath);
var ado = WScript.CreateObject("ADODB.Stream");
ado.Type = 2; // adTypeText = 2
ado.CharSet = "iso-8859-1"; // right code page for output (no adjustments)
//ado.Mode=2;
ado.Open();
// setting the 22th byte to 32
if (flag) {
lnkChars[21]=String.fromCharCode(32);
} else {
lnkChars[21]=String.fromCharCode(0);
}
ado.WriteText(lnkChars.join(""));
ado.SaveToFile(lnkPath, 2);
ado.Close();
}
function examine(lnkPath) {
var fs = new ActiveXObject("Scripting.FileSystemObject");
if (!fs.FileExists(lnkPath)) {
WScript.Echo("File " + lnkPath + " does not exist");
WScript.Quit(2);
}
var oWS = new ActiveXObject("WScript.Shell");
var oLink = oWS.CreateShortcut(lnkPath);
WScript.Echo("");
WScript.Echo(lnkPath + " properties:");
WScript.Echo("");
WScript.Echo("Target:" + oLink.TargetPath);
WScript.Echo("Icon Location:" + oLink.IconLocation);
WScript.Echo("Description:" + oLink.Description);
WScript.Echo("Hotkey:" + oLink.HotKey );
WScript.Echo("Working Directory:" + oLink.WorkingDirectory);
WScript.Echo("Window style:" + oLink.WindowStyle);
WScript.Echo("Admin Permissions:" + hasAdminPermissions(lnkPath));
WScript.Quit(0);
}
if (WScript.Arguments.Length==1 || args.Item(1).toLowerCase() == "-help" || args.Item(1).toLowerCase() == "-h" ) {
printHelp();
WScript.Quit(0);
}
if (WScript.Arguments.Length % 2 == 0 ) {
WScript.Echo("Illegal arguments ");
printHelp();
WScript.Quit(1);
}
if ( args.Item(1).toLowerCase() == "-examine" ) {
var linkfile = args.Item(2);
examine(linkfile);
}
if ( args.Item(1).toLowerCase() == "-edit" ) {
var linkfile = args.Item(2);
edit=true;
}
if(!edit) {
for (var arg = 1;arg<5;arg=arg+2) {
if ( args.Item(arg).toLowerCase() == "-linkfile" ) {
var linkfile = args.Item(arg+1);
}
if (args.Item(arg).toLowerCase() == "-target") {
var target = args.Item(arg+1);
}
}
}
if (typeof linkfile === 'undefined') {
WScript.Echo("Link file not defined");
printHelp();
WScript.Quit(2);
}
if (typeof target === 'undefined' && !edit) {
WScript.Echo("Target not defined");
printHelp();
WScript.Quit(3);
}
var oWS = new ActiveXObject("WScript.Shell");
var oLink = oWS.CreateShortcut(linkfile);
if(typeof target === 'undefined') {
var startIndex=3;
} else {
var startIndex=5;
oLink.TargetPath = target;
}
for (var arg = startIndex ; arg<args.Length;arg=arg+2) {
if (args.Item(arg).toLowerCase() == "-linkarguments") {
oLink.Arguments = args.Item(arg+1);
}
if (args.Item(arg).toLowerCase() == "-description") {
oLink.Description = args.Item(arg+1);
}
if (args.Item(arg).toLowerCase() == "-hotkey") {
oLink.HotKey = args.Item(arg+1);
}
if (args.Item(arg).toLowerCase() == "-iconlocation") {
oLink.IconLocation = args.Item(arg+1);
}
if (args.Item(arg).toLowerCase() == "-windowstyle") {
oLink.WindowStyle = args.Item(arg+1);
}
if (args.Item(arg).toLowerCase() == "-workingdirectory" || args.Item(arg).toLowerCase() == "-workdir") {
oLink.WorkingDirectory = args.Item(arg+1);
}
if (args.Item(arg).toLowerCase() == "-adminpermissions") {
if(args.Item(arg+1).toLowerCase() == "yes") {
var adminPermissions= true;
} else if(args.Item(arg+1).toLowerCase() == "no") {
var adminPermissions= false;
} else {
WScript.Echo("Illegal arguments (admin permissions)");
WScript.Quit(55);
}
}
}
oLink.Save();
if (!(typeof adminPermissions === 'undefined')) {
setAdminPermissions(linkfile ,adminPermissions);
}
Copy path