Solved

Using WSH to update REG_MULTI_SZ data type

Posted on 2000-03-15
4
1,555 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
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This is about my first experience with programming Arduino.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

821 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