Solved

Using WSH to update REG_MULTI_SZ data type

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

786 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