home *** CD-ROM | disk | FTP | other *** search
/ Chip 2009 November / Chip_2009.11_CD.iso / I386 / nusrmgr.cp_ / nusrmgr.cpl / HTML / NUSRMGR.JS < prev    next >
Encoding:
Text File  |  2008-04-14  |  7.9 KB  |  360 lines

  1. var g_bOsPersonal = false;
  2. var g_oUserList = null;
  3. var g_oSelectedUser = null;
  4. var g_strLoggedOnUserName = null;
  5. var g_szInitialTask = null;
  6. var g_bInitialTaskCompleted = false;
  7. var g_bRunningAsOwner = false;
  8. var g_bDeleteFiles = false;
  9. var g_oShell = null;
  10. function GetShell()
  11. {
  12. if (null == g_oShell)
  13. g_oShell = new ActiveXObject("Shell.Application");
  14. return g_oShell;
  15. }
  16. var g_oWShell = null;
  17. function GetWShell()
  18. {
  19. if (null == g_oWShell)
  20. g_oWShell = new ActiveXObject("WScript.Shell");
  21. return g_oWShell;
  22. }
  23. var g_oLocalMachine = null;
  24. function GetLocalMachine()
  25. {
  26. if (null == g_oLocalMachine)
  27. g_oLocalMachine = new ActiveXObject("Shell.LocalMachine");
  28. return g_oLocalMachine;
  29. }
  30. var g_szAdminAccountName = null;
  31. function GetAdminName()
  32. {
  33. if (!g_szAdminAccountName)
  34. {
  35. g_szAdminAccountName = GetLocalMachine().AccountName(500); 
  36. if (!g_szAdminAccountName)
  37. g_szAdminAccountName = "Administrator";
  38. }
  39. return g_szAdminAccountName;
  40. }
  41. var g_szGuestAccountName = null;
  42. function GetGuestName()
  43. {
  44. if (!g_szGuestAccountName)
  45. {
  46. g_szGuestAccountName = GetLocalMachine().AccountName(501); 
  47. if (!g_szGuestAccountName)
  48. g_szGuestAccountName = "Guest";
  49. }
  50. return g_szGuestAccountName;
  51. }
  52. function IsSelf()
  53. {
  54. if (!g_oSelectedUser || !g_strLoggedOnUserName)
  55. return false;
  56. return (g_oSelectedUser.setting("LoginName").toLowerCase() == g_strLoggedOnUserName);
  57. }
  58. function GetUserDisplayName(oUser)
  59. {
  60. var szDisplayName = oUser.setting("DisplayName");
  61. if (!szDisplayName)
  62. szDisplayName = oUser.setting("LoginName");
  63. if (szDisplayName && szDisplayName.length > 20)
  64. {
  65. szDisplayName = szDisplayName.substring(0,17) + "...";
  66. }
  67. if (szDisplayName) szDisplayName = szDisplayName.replace(/</g, "<");
  68. return szDisplayName;
  69. }
  70. function CountOwners()
  71. {
  72. var cOwners = 0;
  73. var cUsers = g_oUserList.length;
  74. var strAdmin = GetAdminName().toLowerCase();
  75. for (var i = 0; i < cUsers && cOwners < 2; i++)
  76. {
  77. var oUser = g_oUserList(i);
  78. if ((3 == oUser.setting("AccountType")) && (oUser.setting("LoginName").toLowerCase() != strAdmin))
  79. ++cOwners;
  80. }
  81. return cOwners;
  82. }
  83. function OnKeySelect(iTab, oEvent)
  84. {
  85. if (null == oEvent)
  86. oEvent = window.event;
  87. if (oEvent.keyCode == 27) 
  88. {
  89. g_Navigator.back();
  90. }
  91. else if (oEvent.keyCode == 32) 
  92. {
  93. oEvent.returnValue = false;
  94. oEvent.srcElement.click();
  95. }
  96. else if (!oEvent.altKey) 
  97. {
  98. var oTarget = null;
  99. switch (oEvent.keyCode)
  100. {
  101. case 37: 
  102. oTarget = oEvent.srcElement.leftElem;
  103. break;
  104. case 38: 
  105. oTarget = oEvent.srcElement.upElem;
  106. break;
  107. case 39: 
  108. oTarget = oEvent.srcElement.rightElem;
  109. break;
  110. case 40: 
  111. oTarget = oEvent.srcElement.downElem;
  112. break;
  113. }
  114. if (oTarget != null)
  115. {
  116. oEvent.srcElement.tabIndex = -1;
  117. oTarget.tabIndex = (null != iTab) ? iTab : 0;
  118. oTarget.focus();
  119. oEvent.returnValue = false;
  120. }
  121. }
  122. }
  123. function SetRelativeTasks(aTasks, iTab)
  124. {
  125. var cTasks = aTasks.length;
  126. var oPrevA = null;
  127. for (var i = 0; i < cTasks; i++)
  128. {
  129. var oTask = aTasks[i];
  130. if (oTask.style.display != 'none')
  131. {
  132. var oAnchor = oTask.getElementsByTagName("A")[0];
  133. if (oAnchor)
  134. {
  135. if (oPrevA)
  136. {
  137. oPrevA.downElem = oAnchor;
  138. oAnchor.upElem = oPrevA;
  139. }
  140. else
  141. oAnchor.tabIndex = (null != iTab) ? iTab : 0;
  142. oPrevA = oAnchor;
  143. }
  144. }
  145. }
  146. }
  147. function PopulateLeftPane(szRelatedTasks, szLearnAbout, szDescription)
  148. {
  149. if (szDescription && szDescription.length > 0)
  150. {
  151. idDescription.innerHTML = szDescription;
  152. idDescription.style.display = 'block';
  153. }
  154. else
  155. idDescription.style.display = 'none';
  156. if (szRelatedTasks && szRelatedTasks.length > 0)
  157. {
  158. idRelatedTaskLinks.innerHTML = szRelatedTasks;
  159. idRelatedTasks.style.display = 'block';
  160. SetRelativeTasks(idRelatedTaskLinks.children, 2);
  161. }
  162. else
  163. idRelatedTasks.style.display = 'none';
  164. if (szLearnAbout && szLearnAbout.length > 0)
  165. {
  166. idLearnAboutLinks.innerHTML = szLearnAbout;
  167. idLearnAbout.style.display = 'block';
  168. SetRelativeTasks(idLearnAboutLinks.children, 2);
  169. }
  170. else
  171. idLearnAbout.style.display = 'none';
  172. }
  173. function CreateUserDisplayHTML2(szName, szSubtitle, szPicture)
  174. {
  175. return '<TABLE cellspacing=0 cols=2 cellpadding=0><TD style="width:15mm;padding:1mm;text-align:center;"><IMG src="'+szPicture+'"/></TD><TD style="padding:1mm"><H3>'+szName+'</H3><H4>'+szSubtitle+'</H4></TD></TABLE>';
  176. }
  177. var g_AccountProps = new Array(L_Guest_Property, L_Limited_Property, L_UnknownAcct_Property, L_Owner_Property);
  178. function CreateUserDisplayHTML(oUser, szSubtitle)
  179. {
  180. if (!szSubtitle)
  181. {
  182. szSubtitle = g_AccountProps[oUser.setting("AccountType")];
  183. if (oUser.passwordRequired)
  184. szSubtitle += '<BR>' + L_Password_Property;
  185. }
  186. return CreateUserDisplayHTML2(GetUserDisplayName(oUser), szSubtitle, oUser.setting("Picture"));
  187. }
  188. var g_HelpWindow = null;
  189. var g_szHelpUrl = null;
  190. function LaunchHelp(szHTM)
  191. {
  192. if (szHTM && szHTM.length > 0)
  193. {
  194. if (null == g_HelpWindow)
  195. {
  196. var args = new Object;
  197. args.mainWindow = window;
  198. args.szHTM = szHTM;
  199. if (null == g_szHelpUrl)
  200. g_szHelpUrl = GetWShell().ExpandEnvironmentStrings("MS-ITS:%windir%\\help\\nusrmgr.chm::/");
  201. g_HelpWindow = window.showModelessDialog(g_szHelpUrl + "HelpFrame.htm", args, "border=thick; center=0; dialogWidth=30em; dialogHeight=34em; help=0; minimize=1; maximize=1; resizable=1; status=0;");
  202. }
  203. else
  204. {
  205. try
  206. {
  207. g_HelpWindow.ShowHelp(g_szHelpUrl + szHTM);
  208. }
  209. catch (e)
  210. {
  211. g_HelpWindow.close();
  212. g_HelpWindow = null;
  213. }
  214. }
  215. }
  216. }
  217. function EnableGuest(bEnable)
  218. {
  219. if (!bEnable)
  220. {
  221. var oGuest = g_oUserList(GetGuestName());
  222. if (oGuest && oGuest.isLoggedOn)
  223. {
  224. alert(L_DisableGuestInUse_ErrorMessage);
  225. return false;
  226. }
  227. }
  228. try
  229. {
  230. if (bEnable)
  231. {
  232. GetLocalMachine().EnableGuest(1);
  233. g_oSelectedUser = null;
  234. g_oUserList = null;
  235. g_oUserList = new ActiveXObject("Shell.Users");
  236. }
  237. else
  238. GetLocalMachine().DisableGuest(1);
  239. }
  240. catch (e)
  241. {
  242. }
  243. g_Navigator.navigate("mainpage2.htm", true);
  244. }
  245. function PageInit()
  246. {
  247. try
  248. {
  249. g_oUserList = new ActiveXObject("Shell.Users");
  250. }
  251. catch (e)
  252. {
  253. alert(L_SHGinaLoad_ErrorMessage);
  254. window.close();
  255. return;
  256. }
  257. g_bOsPersonal = GetShell().GetSystemInformation("IsOS_Personal");
  258. g_oSelectedUser = g_oUserList.currentUser;
  259. if (g_oSelectedUser)
  260. {
  261. g_strLoggedOnUserName = g_oSelectedUser.setting("LoginName").toLowerCase();
  262. g_bRunningAsOwner = (3 == g_oSelectedUser.setting("AccountType"));
  263. }
  264. else if (false == g_bOsPersonal)
  265. {
  266. g_bRunningAsOwner = true;
  267. }
  268. else
  269. {
  270. alert(L_NoCurrentUser_ErrorMessage);
  271. window.close();
  272. return;
  273. }
  274. if (idUM.commandLine)
  275. {
  276. var iInitialTask = idUM.commandLine.indexOf("initialTask=");
  277. if (-1 != iInitialTask)
  278. {
  279. g_szInitialTask = idUM.commandLine.substring(iInitialTask+12);
  280. }
  281. }
  282. g_Navigator = new Navigator(idContent);
  283. if (g_Navigator)
  284. g_Navigator.navigate(g_bRunningAsOwner ? "mainpage2.htm" : "mainpage.htm");
  285. }
  286. var g_Navigator = null;
  287. function push(url)
  288. {
  289. if (url)
  290. {
  291. if (this.current < 0 || url != this.stack[this.current])
  292. this.stack[++this.current] = url;
  293. this.stack.length = this.current + 1;
  294. }
  295. }
  296. function navigate(urlTo, bTrim)
  297. {
  298. if (this.current < 0)
  299. bTrim = false;
  300. if (bTrim)
  301. {
  302. while (this.current >= 0)
  303. {
  304. this.stack.length = this.current + 1;
  305. if (urlTo == this.stack[this.current])
  306. break;
  307. if (0 == this.current)
  308. {
  309. this.push(urlTo);
  310. break;
  311. }
  312. --this.current;
  313. }
  314. }
  315. else
  316. {
  317. this.push(urlTo);
  318. }
  319. this.SetBtnState();
  320. this.frame.navigate(urlTo);
  321. }
  322. function back(nCount)
  323. {
  324. if (this.current > 0)
  325. {
  326. if (!nCount)
  327. nCount = 1;
  328. if (-1 == nCount)
  329. this.current = 0;
  330. else
  331. this.current = Math.max(0, this.current - nCount);
  332. this.frame.navigate(this.stack[this.current]);
  333. }
  334. this.SetBtnState();
  335. }
  336. function forward()
  337. {
  338. if (this.current < this.stack.length - 1)
  339. this.frame.navigate(this.stack[++this.current]);
  340. this.SetBtnState();
  341. }
  342. function SetBtnState()
  343. {
  344. idToolbar.enabled(0) = (this.current > 0);
  345. idToolbar.enabled(1) = (this.current != this.stack.length - 1);
  346. idToolbar.enabled(2) = (this.current > 0);
  347. }
  348. function Navigator(frame)
  349. {
  350. this.push = push;
  351. this.navigate = navigate;
  352. this.back = back;
  353. this.forward = forward;
  354. this.SetBtnState = SetBtnState;
  355. this.frame = frame;
  356. this.current = -1;
  357. this.stack = new Array();
  358. this.SetBtnState();
  359. }
  360.