Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using WSH to update REG_MULTI_SZ data type

Posted on 2000-03-15
4
Medium Priority
?
1,589 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 400 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
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 …
Simple Linear Regression

971 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