Solved

Using WSH to update REG_MULTI_SZ data type

Posted on 2000-03-15
4
1,565 Views
Last Modified: 2012-08-14
I need to add a registry value which has a data type of REG_MULTI_SZ.  I was hoping to do it with WSH (Windows Scripting Host) using VB but the documentation says that the RegWrite method cannot handle REG_MULTI_SZ data.

Is anyone aware of another means to accomplish this with WSH?
0
Comment
Question by:swartwe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Expert Comment

by:ramshank
ID: 2637930
Try the following


RegRead Method
--------------
The following code segment will return the value of the registry key specified in
the strPath variable. The code below can also help in determining the data type
of the key being access. The following table shows the return value when using
the TypeName function on the registry key.

+---------------------------------------------------+
| Registry Key  | Return Data Type (using TypeName) |
+---------------------------------------------------+
| REG_SZ        | String                            |
+---------------------------------------------------+
| REG_EXPAND_SZ | String                            |
+---------------------------------------------------+
| REG_MULTI_SZ  | Variant Array                     |
+---------------------------------------------------+
| REG_DWORD     | Long                              |
+---------------------------------------------------+
| REG_BINARY    | Variant Array                     |
+---------------------------------------------------+

   Set WshShell = CreateObject("WScript.Shell")
   strPath = "HKCU\MyRegKey\Entry\Value1"
   varRegVal = WshShell.RegRead(strPath)
   WScript.Echo TypeName(varRegVal)
   'Check to see if the value is an array of values, then loop through them
   If VarType(varRegVal) And vbArray Then
       For i = LBound(varRegVal) To UBound(varRegVal)
           WScript.Echo varRegVal(i)
       Next
   Else
       WScript.Echo varRegVal
   End If
0
 

Author Comment

by:swartwe
ID: 2638392
While I appreciate the response and find it interesting, it does not answer my question ("I need to add a registry value which has a data type of REG_MULTI_SZ.").  Regrettably, I must reject this response.
0
 

Accepted Solution

by:
bxt earned 100 total points
ID: 2771399
I have run into the same problem.  I was hoping that somebody else would have answered this.  My only solution has been to create a program called RegMultiSz that convets a REG_SZ key to a REG_MULTI_SZ key.

I run it from script using a command line variable which is the key I want to change e.g.

REG_MULTI_SZ HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\abc

Here is the code, I can send you the .EXE if it is of use to you

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
      char hive[256];      
      char subkey[1024];
      char lastsubkey[1024];
      char key[256];
      char seps[]   = "\\";
      char *token;

    /* Establish string and get the first token: */
    token = strtok( lpCmdLine, seps );  
      strcpy(hive,token);
      strcpy(subkey,"");
      /* Get next token: */
      token = strtok( NULL, seps );
      while( token != NULL )  
      {
            strcat(subkey,token);            
            strcat(subkey,"\\");
            strcpy(key,token);
          /* Get next token: */
            token = strtok( NULL, seps );
            if (token!=NULL)
                  strcpy(lastsubkey,subkey);
            else
                  strcpy(subkey,lastsubkey);
      }      
      

      HKEY hKey;
      if (strcmp(hive,"HKEY_CLASSES_ROOT")==0)
            hKey=HKEY_CLASSES_ROOT;
      else if (strcmp(hive,"HKEY_CURRENT_CONFIG")==0)
            hKey=HKEY_CURRENT_CONFIG;
      else if (strcmp(hive,"HKEY_CURRENT_USER")==0)
                  hKey=HKEY_CURRENT_USER;
      else if (strcmp(hive,"HKEY_LOCAL_MACHINE")==0)
                  hKey=HKEY_LOCAL_MACHINE;
      else if (strcmp(hive,"HKEY_USERS")==0)
                  hKey=HKEY_USERS;      

      if (RegOpenKey(hKey,subkey,&hKey)==ERROR_SUCCESS)
      {
            BYTE sValue[80];
            DWORD nSize=80;

            if (RegQueryValueEx(hKey, key, NULL, NULL, sValue, &nSize)==ERROR_SUCCESS)
            {
                  sValue[nSize]=0;
                  RegSetValueEx(hKey, key, 0, REG_MULTI_SZ, (BYTE*)(LPCSTR)sValue, nSize+1);
            }
            RegCloseKey(hKey);  
      }

      return 0;
}
0
 

Author Comment

by:swartwe
ID: 2771460
While my preference was to add a REG_MULTI_SZ string using WSH, as of now, I don't think that it can be done with WSH.  Because of this conclusion, a couple of weeks ago I decided to write my own utility (I used the same API functions which you used in your utility).

I am giving you an excellent grade because you did provide a means by which to accomplish my needs (using the same approach that I ultimately chose).

I appreciate your help along with your offer to send me an exe (However, I won't be needing an exe).  

Thank you.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question