Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

538 lines
13 KiB

  1. <?XML version="1.0" ?>
  2. <package>
  3. <comment>
  4. Used in International and US BVT
  5. </comment>
  6. <comment>
  7. Helps eliminate the need to download of perl executables
  8. and scripts to BVT machine.
  9. Sample destinations one may need to be wable to write:
  10. AppData C:\WINDOWS\system32\config\systemprofile\Application Data
  11. Cookies C:\Documents and Settings\Default User.WINDOWS\Cookies
  12. Desktop C:\WINDOWS\system32\config\systemprofile\Desktop
  13. Favorites C:\WINDOWS\system32\config\systemprofile\Favorites
  14. NetHood C:\WINDOWS\system32\config\systemprofile\NetHood
  15. Personal C:\WINDOWS\system32\config\systemprofile\My Documents
  16. PrintHood C:\WINDOWS\system32\config\systemprofile\PrintHood
  17. Recent C:\WINDOWS\system32\config\systemprofile\Recent
  18. SendTo C:\WINDOWS\system32\config\systemprofile\SendTo
  19. Start Menu C:\WINDOWS\system32\config\systemprofile\Start Menu
  20. Templates C:\WINDOWS\system32\config\systemprofile\Templates
  21. Programs C:\WINDOWS\system32\config\systemprofile\Start Menu\Programs
  22. Startup C:\WINDOWS\system32\config\systemprofile\Start Menu\Programs\Startup
  23. Local Settings C:\WINDOWS\system32\config\systemprofile\Local Settings
  24. Local AppData C:\WINDOWS\system32\config\systemprofile\Local Settings\Application Data
  25. Cache C:\Documents and Settings\Default User.WINDOWS\Local Settings\Temporary Internet Files
  26. History C:\Documents and Settings\Default User.WINDOWS\Local Settings\History
  27. My Pictures
  28. My Music
  29. Fonts C:\WINDOWS\Fonts
  30. </comment>
  31. <job>
  32. <resource id ="destination">AllUsersDesktop</resource>
  33. <resource id="icon">%SystemRoot%\system32\SHELL32.dll</resource>
  34. <resource id="action">%SYSTEMROOT%\notepad.exe</resource>
  35. <resource id="label">Safe Boot.lnk</resource>
  36. <resource id="index">132</resource>
  37. <resource id="comment">Reboot to SAFE</resource>
  38. <resource id="Usage">
  39. Name:
  40. %SELF%
  41. Creates a shortcut for given app at specified special folder [e.g. DESKTOP].
  42. Usage:
  43. %SELF% -c:%TEXT% -l:%NAME% -x:%EXEC% -h -d -i:%NUMBER% -y:%FOLDER%
  44. Where
  45. -h show this message
  46. -d enable debugging
  47. -y the destination special folder name. Default: %DESTINATION%
  48. -l the name for the shortcut. Default: "%LABEL%"
  49. -x executable to provide shortcut to. Default: %ACTION%
  50. -i icon index in shell32.dll. Default: %INDEX%
  51. -c optional comment for the shortcut. Default: "%COMMENT%"
  52. Note: You may use single or double quotes to delimit arguments with spaces,
  53. but not the mix.
  54. Note: No shortcut will be created if the %EXEC% is not found on the system.
  55. Existing shortcut will not be overwritten either.
  56. </resource>
  57. <script language="VBScript">
  58. <![CDATA[
  59. sub showUsage
  60. Const VBEXPECTED = 5
  61. on error resume next
  62. Dim oGenRplaceVarNamXp
  63. Dim oExRplaceVarNamXp
  64. Dim aoRplaceMatches, oMatch, sMatch, sLabel, sResource
  65. Set oGenRplaceVarNamXp = new RegExp
  66. Set oExRplaceVarNamXp = new RegExp
  67. With oGenRplaceVarNamXp
  68. .Global = True
  69. .IgnoreCase = True
  70. .Pattern = "%\w+%"
  71. End With
  72. With oExRplaceVarNamXp
  73. .Global = True
  74. .IgnoreCase = True
  75. .Pattern = "%\w+%"
  76. End With
  77. Dim sLine,asTest
  78. asTest = ReadResource("Usage")
  79. For Each sLine in asTest
  80. sLine = Replace(sLine, "%SELF%", WScript.ScriptName,1,10)
  81. Set aoRplaceMatches = oGenRplaceVarNamXp.Execute(sLine)
  82. For Each oMatch in aoRplaceMatches
  83. sMatch = oMatch.value
  84. sMatch = UCase(Mid(sMatch, 2, Len(sMatch)-2))
  85. sLabel = LCase(sMatch)
  86. Err.clear
  87. sResource = GetResource(sLabel)
  88. If err = 0 Then
  89. sMatch = sResource
  90. ElseIf err = VBEXPECTED Then
  91. sMatch = "<" & sMatch & ">"
  92. Else
  93. Raise Err
  94. End If
  95. oExRplaceVarNamXp.Pattern = oMatch.value
  96. sLine = oExRplaceVarNamXp.Replace(sLine, sMatch)
  97. Next
  98. WScript.echo sLine
  99. Next
  100. WScript.Quit(0)
  101. End sub
  102. ]]>
  103. </script>
  104. <script language="VBScript">
  105. <![CDATA[
  106. option explicit
  107. Function ReadResource(sPresId)
  108. On Error resume next
  109. Dim WshShell
  110. Set WshShell = CreateObject("WScript.Shell")
  111. Dim sPRes, asRes, uRes, tsRes
  112. sPREs = GetResource(sPresId)
  113. If Err.number <> 0 Then
  114. Wscript.echo err.number & " " & err.description
  115. ' The Error description are not informative when failed getresource
  116. IF Err.number = 7 Then
  117. Wscript.echo chr(9) & "Null resource: " & _
  118. sPresId
  119. End If
  120. IF Err.number = 5 Then
  121. Wscript.echo chr(9) & "Undefined resource: " & _
  122. sPresId
  123. End If
  124. Wscript.quit
  125. End If
  126. asRes = Split(WshShell.ExpandEnvironmentStrings(sPRes), VBNEWLINE)
  127. Set ures = CreateObject("Scripting.Dictionary")
  128. For Each tsRes in asRes
  129. If 0 <> Len(tsRes) Then
  130. uRes(tsRes) = 1
  131. End If
  132. Next
  133. Dim tResource
  134. tResource = uRes.Keys
  135. If uBound(tResource) = 0 Then
  136. ReadResource = tResource(0)
  137. Else
  138. ReadResource = tResource
  139. End If
  140. Set WshShell = Nothing
  141. Set uRes = Nothing
  142. End Function
  143. ]]>
  144. </script>
  145. <script language="VBScript">
  146. <![CDATA[
  147. Option Explicit
  148. Dim spDestination
  149. Dim opshell, opShortCut, spIconPath, spLinkLabel, spLinkAction, spLinkComment, npIconIndex
  150. Dim siLinkComment, siLinkLabel, siLinkAction, siDestination, niIconIndex, Debug, Help, apCopyArgs, nRawArg
  151. Dim sLinkTargetPath, aActionSplit, sDescriptionSplit
  152. Set opShell = CreateObject("WScript.Shell")
  153. spDestination = opShell.SpecialFolders.Item(CStr(GetResource("destination")))
  154. spLinkLabel = CStr(GetResource("label"))
  155. spIconPath = opShell.ExpandEnvironmentStrings(CStr(GetResource("icon")))
  156. spLinkAction = opShell.ExpandEnvironmentStrings(CStr(GetResource("action")))
  157. spLinkComment = CStr(GetResource("comment"))
  158. npIconIndex = CInt(GetResource("index"))
  159. apCopyArgs = Array()
  160. Redim apCopyArgs (Wscript.arguments.Count)
  161. For nRawArg = 0 to Wscript.arguments.Count - 1
  162. apCopyArgs(nRawArg) = Wscript.arguments(nRawArg)
  163. Next
  164. apCopyArgs = reQuoteObjArgs(apCopyArgs)
  165. Call GetParams("h d c: l: x: i: y:", _
  166. "Help Debug siLinkComment siLinkLabel siLinkAction niIconIndex siDestination", apCopyArgs)
  167. if Help <> "" Then
  168. ShowUsage
  169. End If
  170. if niIconIndex <> "" Then
  171. npIconIndex = CInt(niIconIndex)
  172. End If
  173. if siLinkLabel <> "" Then
  174. spLinkLabel = siLinkLabel
  175. End If
  176. if siLinkAction <> "" Then
  177. spLinkAction = opShell.ExpandEnvironmentStrings(siLinkAction)
  178. End If
  179. if siLinkComment <> "" Then
  180. spLinkComment = siLinkComment
  181. End If
  182. if siDestination <> "" Then
  183. spDestination = opShell.SpecialFolders.Item(CStr(siDestination))
  184. WSCript.echo spDestination
  185. if "" = spDestination Then
  186. WSCript.echo "Unrecognized special folder: " & _
  187. siDestination
  188. WSCript.quit 17
  189. End If
  190. End If
  191. if not bFileExistenceTest(spLinkAction) then
  192. WScript.quit
  193. End If
  194. spIconPath = spIconPath & "," & CStr(npIconIndex)
  195. spLinkLabel = spDestination & "\" & spLinkLabel
  196. If not bFileExistenceTest(spLinkLabel) then
  197. Set opShortCut = opShell.CreateShortcut(spLinkLabel)
  198. aActionSplit = split(spLinkAction, " ")
  199. sLinkTargetPath = aActionSplit(0)
  200. sDescriptionSplit = ""
  201. If UBound(aActionSplit) > 0 Then
  202. For nRawArg = 1 To UBound(aActionSplit)
  203. sDescriptionSplit = sDescriptionSplit & aActionSplit(nRawArg)
  204. Next
  205. With opShortCut
  206. .Description = spLinkComment
  207. .Arguments = sDescriptionSplit
  208. .TargetPath = sLinkTargetPath
  209. .IconLocation = spIconPath
  210. .WorkingDirectory = "%TEMP%"
  211. .save
  212. End With
  213. Else
  214. With opShortCut
  215. .Description = spLinkComment
  216. .TargetPath = spLinkAction
  217. .IconLocation = spIconPath
  218. .WorkingDirectory = "%TEMP%"
  219. .save
  220. End With
  221. End If
  222. End If
  223. Set opShortCut = Nothing
  224. Set opShell = Nothing
  225. WSCript.quit
  226. Function bFileExistenceTest(spLine)
  227. Dim aopExistenceTests, opExistenceTest, opNameSpace, sPreparedQueryName
  228. Dim aspSplitFullName, spFullName
  229. Dim spLinkAction
  230. Set opNameSpace = GetObject("winmgmts:root\cimv2")
  231. If isObject(opNameSpace) then ' a successful connection to winmgmts service
  232. bFileExistenceTest = False
  233. For Each spFullName in split(spLine, " ")
  234. aspSplitFullName = split(spFullName, "\")
  235. spFullName = join(aspSplitFullName, "\\")
  236. sPreparedQueryName = "Select * from cim_datafile where name = """ & spFullName & """ "
  237. Set aopExistenceTests = opNameSpace.execQuery("Select * from cim_datafile where name = """ & _
  238. spFullName & _
  239. """", "WQL", 0)
  240. For each opExistenceTest in aopExistenceTests
  241. If True = Debug Then
  242. Wscript.echo opExistenceTest.name & " is present on this system"
  243. End If
  244. bFileExistenceTest = True
  245. Next
  246. Set opExistenceTest = nothing
  247. Set aopExistenceTests = nothing
  248. Next
  249. Else
  250. Wscript.echo "cannot access namespace root\cimv2"
  251. End if
  252. Set opNameSpace = nothing
  253. End Function
  254. Public Function reQuoteObjArgs(objArgs)
  255. Dim sLabelVar, sFoundLabel, sArgsDictionary, sArg, oArgs, nArg
  256. Dim poQuotedCheckRegEx, poStringCheckRegEx, psQuotedCheckPt
  257. Dim sConcatArgs, aRepArgs, spBadQuotedPart, spGoodQuotedPart, apQuoted
  258. sConcatArgs = join(objArgs, " ")
  259. psQuotedCheckPt = "\'[^\']+\'"
  260. Set poQuotedCheckRegEx = New RegExp
  261. With poQuotedCheckRegEx
  262. .Global = True
  263. .IgnoreCase = True
  264. .Pattern = psQuotedCheckPt
  265. End with
  266. Set poStringCheckRegEx = New RegExp
  267. With poQuotedCheckRegEx
  268. .Global = True
  269. .IgnoreCase = True
  270. .Pattern = psQuotedCheckPt
  271. End with
  272. If True = poQuotedCheckRegEx.Test(sConcatArgs) Then
  273. Set apQuoted = poQuotedCheckRegEx.Execute(sConcatArgs)
  274. For each spBadQuotedPart in apQuoted
  275. spGoodQuotedPart = Replace(spBadQuotedPart," ", "0x20", 1, 1000)
  276. spGoodQuotedPart = Mid(spGoodQuotedPart,2, Len(spGoodQuotedPart) -2 )
  277. poStringCheckRegEx.Pattern = Replace(spBadQuotedPart, "\", "\\", 1 ,100)
  278. sConcatArgs = poStringCheckRegEx.Replace(sConcatArgs, spGoodQuotedPart)
  279. Next
  280. aRepArgs = Split(sConcatArgs, " ")
  281. oArgs = Array()
  282. Redim oArgs (ubound(aRepArgs) + 1)
  283. For nArg = 0 To ubound(aRepArgs)
  284. oArgs(nArg) = Replace(aRepArgs(nArg), "0x20", " ", 1, 100)
  285. Next
  286. reQuoteObjArgs = oArgs
  287. Else
  288. reQuoteObjArgs = objArgs
  289. End If
  290. End Function
  291. Public Sub GetParams(sFlags, sVarNames, objArgs)
  292. Dim sLabelVar, sFoundLabel, sArgsDictionary
  293. Dim poKnownSwitchRegEx, psMaskKnownSwitch, nArg, mma, nma, nextlen, objargsnamed
  294. Dim aFlags, aVarNames ' Arrays to split the sFlags and sVarNames
  295. Set poKnownSwitchRegEx = New RegExp
  296. Set sArgsDictionary = CreateObject("Scripting.Dictionary")
  297. psMaskKnownSwitch = "[-/]\w+:?\b"
  298. poKnownSwitchRegEx.Global = True
  299. poKnownSwitchRegEx.IgnoreCase = True
  300. poKnownSwitchRegEx.Pattern = psMaskKnownSwitch
  301. If 0 = ubound(objArgs) Then
  302. Exit Sub
  303. End If
  304. For nArg = 0 to uBound(objArgs)
  305. If True = poKnownSwitchRegEx.Test(objArgs(nArg)) Then
  306. Set mmA = poKnownSwitchRegEx.Execute(objArgs(nArg))
  307. If mma.Count <> 1 Then
  308. WScript.echo "Bad RegExp Count"
  309. Err.Raise (1937)
  310. Else
  311. For each nma in mma
  312. NextLen = nma.FirstIndex + nma.Length
  313. sFoundLabel = CStr(Mid(objArgs(nArg), _
  314. 2 + nma.FirstIndex, _
  315. nma.Length - 1))
  316. ' This is not If Right(sFoundLabel,1) = ":" Then
  317. ' required sFoundLabel = Left(sFoundLabel, len(sFoundLabel) - 1 )
  318. ' End If
  319. If NextLen <> len(objArgs(nArg)) Then
  320. sLabelVar = CStr(Mid(objArgs(nArg),NextLen + 1 ))
  321. Else
  322. sLabelVar = True
  323. End If
  324. sArgsDictionary.add sFoundLabel, sLabelVar
  325. Next
  326. End If
  327. End If
  328. Next
  329. aFlags = split(sFlags)
  330. aVarNames = split(sVarNames)
  331. If Ubound(aFlags) <> Ubound(aVarNames) Then
  332. Exit Sub
  333. End If
  334. Dim tnCnt
  335. For tnCnt = 0 to Ubound(aFlags)
  336. If sArgsDictionary.Exists(aFlags(tnCnt)) Then
  337. FeedVar sArgsDictionary(aFlags(tnCnt)), aVarNames(tnCnt)
  338. End If
  339. Next
  340. Set sArgsDictionary = Nothing
  341. Set poKnownSwitchRegEx = Nothing
  342. End Sub
  343. Private Sub FeedVar(sLabelVar, sLabel)
  344. If VarType(sLabelVar) <> vbString Then
  345. Execute(sLabel & "=" & sLabelVar)
  346. Else
  347. Execute(sLabel & "=" & """" & sLabelVar & """" )
  348. End If
  349. End Sub
  350. ]]>
  351. </script>
  352. </job>
  353. </package>