Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4241912
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:22:19+00:00 2026-05-21T03:22:19+00:00

How do I convert the following VBScript code to JScript which is used for

  • 0

How do I convert the following VBScript code to JScript which is used for getting the user profile paths for all users?

Set oWshNet = CreateObject("Wscript.Network")
sComputer = oWshNet.ComputerName
'For remote computer
'sComputer = "some name or IP"
Const HKLM = &H80000002

sProfileRegBase = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" 
Set oReg = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" _ 
                & sComputer & "/root/default:StdRegProv")
Set oWMI = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" _ 
                & sComputer & "/root/cimv2")
Set colItems = oWMI.ExecQuery _ 
                ("Select Name,SID from Win32_UserAccount WHERE Domain = '" _ 
                & sComputer & "'",,48)
For Each oItem In colItems
  sAddInfo = ""
  Wscript.Echo "User name: " & oItem.Name & sAddInfo
  oReg.GetExpandedStringValue HKLM, sProfileRegBase& "\" & oItem.SID, _ 
                  "ProfileImagePath", sProfilePath
  If IsNull(sProfilePath) Then
    sProfilePath = "(none defined)"
  End If <br>
  Wscript.Echo "Profile path: " & sProfilePath
  Wscript.Echo   ' blank line
Next

I was partially succeeded in converting but stuck at 2 things.

  1. Please confirm whether my usage of oReg = GetObject("WinMgmts:\\\\.\\root\\default:StdRegProv"); is correct and is same as the one that was given in the code. If not please suggest the right usage.

  2. What is the equivalent for GetExpandedStringValue in JScript? If there is none, what is the better way to validate if a registry key exists before getting the value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T03:22:20+00:00Added an answer on May 21, 2026 at 3:22 am

    Here is a sample solution: (from http://www.windowsitpro.com/content/content/93402/Listing_05.txt)

    // GetSystemPath.js
    
    var HKEY_LOCAL_MACHINE = 0x80000002;
    var ENVIRONMENT_SUBKEY = "SYSTEM\\CurrentControlSet\\Control"
      + "\\Session Manager\\Environment";
    
    var computer, regprov, method, inparams, outparams, systempath;
    
    // CALLOUT A
    // Step 1: Get an instance of the WMI object.
    computer = ".";
    regprov = GetObject("winmgmts:{impersonationlevel=impersonate}!//"
      + computer + "/root/default:StdRegProv");
    // END CALLOUT A
    
    // CALLOUT B
    // Step 2: Create an InParameters object for the method.
    method = regprov.Methods_.Item("GetExpandedStringValue");
    inparams = method.InParameters.SpawnInstance_();
    // END CALLOUT B
    
    // CALLOUT C
    // Step 3: Set the InParameters object's properties.
    inparams.hDefKey = HKEY_LOCAL_MACHINE;
    inparams.sSubKeyName = ENVIRONMENT_SUBKEY;
    inparams.sValueName = "Path";
    // END CALLOUT C
    
    // CALLOUT D
    // Step 4: Call ExecMethod_ to return an OutParameters object.
    outparams = regprov.ExecMethod_(method.Name, inparams);
    // END CALLOUT D
    
    // CALLOUT E
    // Step 5: The OutParameters object contains the method's results.
    if (outparams.ReturnValue == 0) {
      systempath = outparams.sValue;
      WScript.Echo(systempath);
    }
    // END CALLOUT E
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to convert following batch file code to Linux shell script? @echo off set
HI, I am trying to convert the following vba code to c# and i
I have the following code to convert a distinguishedName to a sAMAccountName: Dim de
We try to convert from string to Byte[] using the following Java code: String
Take the following code for example; if (Convert.ToString(frm.WindowState) == Minimized) Layout.WindowState = Maximized; else
I'm using php and I have the following code to convert an absolute path
How to convert following vb code in to c#? Dim request As HttpWebRequest =
I am a java devloper and I wish to convert following code to java
Need to convert the following code from Ruby to C#. However I'm kind of
I'm trying to convert the following scriptlet code to EL. I tried the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.