Quantcast
Channel: MSDN Blogs
Viewing all articles
Browse latest Browse all 29128

Updating my HTML Application for Configuring your WebDAV Redirector Settings

$
0
0

A couple of years ago I wrote a blog that was titled "How to create an HTML Application to configure your WebDAV Redirector settings", where I showed how to use HTMLA to create a simple editor for most of the WebDAV Redirector settings. These settings have no other user interface, so prior to my blog post users had to manually edit the registry in order to modify their WebDAV Redirector settings.

Click image to expand

In the past two years since I wrote that blog, I have found myself using that simple application so often that I now keep it in my personal utilities folder on my SkyDrive so I can have it with me no matter where I am travelling. But that being said, I ran into an interesting situation the other day that made me want to update the application, so I thought that it was time to write a new blog with the updated changes.

Here's what happened - I had opened my application for modifying my WebDAV Redirector settings, but then something happened which distracted me, and then I headed off to lunch before I committed my changes to the registry. When I came back to my office, I noticed that my WebDAV Redirector settings application was still open and I clicked the Exit Application button. The application popped up a dialog which informed me that I had changes that hadn't been saved to the registry, but I forgot what they were. This put me in a quandary - I could simply click Yes and hope for the best, or I could click No and lose whatever changes that I had made and re-open the application to start over.

It was at that time that I thought to myself, "If only I had a Reset Values button..."

By now you can probably see where this blog is going, and here's what the new application looks like - it's pretty much the same as the last application, with the additional button that allows you to reset your values without exiting the application. (Note - the application will prompt you for confirmation if you attempt to reset the values and you have unsaved changes.)

Click image to expand

Creating the Updated HTML Application

To create this HTML Application, you need to use the same steps as my last blog: save the following HTMLA code as "WebDAV Redirector Settings.hta" to your computer, and then double-click its icon to run the application.

<html><head><title>WebDAV Redirector Settings</title><HTA:APPLICATIONAPPLICATIONNAME="WebDAV Redirector Settings"ID="WebDAV Redirector Settings"VERSION="1.0"BORDER="dialog"BORDERSTYLE="static"INNERBORDER="no"SYSMENU="no"MAXIMIZEBUTTON="no"MINIMIZEBUTTON="no"SCROLL="no"SCROLLFLAT="yes"SINGLEINSTANCE="yes"CONTEXTMENU="no"SELECTION="no"/><scriptlanguage="vbscript">' ----------------------------------------' Start of main code section.' ----------------------------------------Option ExplicitConst intDialogWidth = 700Const intDialogHeight = 620Const HKEY_LOCAL_MACHINE = &H80000002Const strWebClientKeyPath = "SYSTEM\CurrentControlSet\Services\WebClient\Parameters"Const strLuaKeyPath = "Software\Microsoft\Windows\CurrentVersion\Policies\System"Dim objRegistryDim blnHasChanges' ----------------------------------------' Start the application.' ----------------------------------------Sub Window_OnLoadOnErrorResumeNext' Set up the UI dimensions.
  Self.resizeTo intDialogWidth,intDialogHeight
  Self.moveTo (Screen.AvailWidth - intDialogWidth) / 2, _
    (Screen.AvailHeight - intDialogHeight) / 2' Retrieve the current settings.
  Document.all.TheBody.ClassName = "hide"Set objRegistry = GetObject( _"winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")Call CheckForLUA()Call GetValues()
  Document.All.TheBody.ClassName = "show"EndSub' ----------------------------------------' Check for User Access Control' ----------------------------------------Sub CheckForLUA()If GetRegistryDWORD(strLuaKeyPath,"EnableLUA",1)<> 0 Then
    MsgBox "User Access Control (UAC) is enabled on this computer."& _
      vbCrLf & vbCrLf & "UAC must be disabled in order to edit "& _"the registry and restart the service for the WebDAV Redirector. "& _"Please disable UAC before running this application again. "& _"This application will now exit.", _
      vbCritical, "User Access Control"
    Self.closeEndIfEndSub' ----------------------------------------' Exit the application.' ----------------------------------------Sub ExitApplication()If blnHasChanges = FalseThenIf MsgBox("Are you sure you want to exit?", _
      vbQuestion Or vbYesNo Or vbDefaultButton2, _"Exit Application") = vbNo ThenExitSubEndIfElseDim intRetVal
    intRetVal = MsgBox("You have unsaved changes. "& _"Do you want to save them before you exit?", _
      vbQuestion Or vbYesNoCancel Or vbDefaultButton1, _"Reset Application")If intRetVal = vbYes ThenCall SetValues()ElseIf intRetVal = vbCancel ThenExitSubEndIfEndIf
  Self.closeEndSub' ----------------------------------------' Reset the application.' ----------------------------------------Sub ResetApplication()If blnHasChanges = TrueThenDim intRetVal
    intRetVal = MsgBox("You have unsaved changes. "& _"Do you want to save them before you reset the values?", _
      vbQuestion Or vbYesNoCancel Or vbDefaultButton1, _"Reset Application")If intRetVal = vbYes ThenCall SetValues()ElseIf intRetVal = vbCancel ThenExitSubEndIfEndIfCall GetValues()EndSub' ----------------------------------------' Flag the application as having changes.' ----------------------------------------Sub FlagChanges()
  blnHasChanges = TrueEndSub' ----------------------------------------' Retrieve the settings from the registry.' ----------------------------------------Sub GetValues()OnErrorResumeNextDim tmpCount,tmpArray,tmpString' Get the radio button valuesCall SetRadioValue(Document.all.BasicAuthLevel, _
    GetRegistryDWORD(strWebClientKeyPath, _"BasicAuthLevel",1))Call SetRadioValue(Document.all.SupportLocking, _
    GetRegistryDWORD(strWebClientKeyPath, _"SupportLocking",1))' Get the text box values
  Document.all.InternetServerTimeoutInSec.Value = _
    GetRegistryDWORD(strWebClientKeyPath, _"InternetServerTimeoutInSec",30)
  Document.all.FileAttributesLimitInBytes.Value = _
    GetRegistryDWORD(strWebClientKeyPath, _"FileAttributesLimitInBytes",1000000)
  Document.all.FileSizeLimitInBytes.Value = _
    GetRegistryDWORD(strWebClientKeyPath, _"FileSizeLimitInBytes",50000000)
  Document.all.LocalServerTimeoutInSec.Value = _
    GetRegistryDWORD(strWebClientKeyPath, _"LocalServerTimeoutInSec",15)
  Document.all.SendReceiveTimeoutInSec.Value = _
    GetRegistryDWORD(strWebClientKeyPath, _"SendReceiveTimeoutInSec",60)
  Document.all.ServerNotFoundCacheLifeTimeInSec.Value = _
    GetRegistryDWORD(strWebClientKeyPath, _"ServerNotFoundCacheLifeTimeInSec",60)' Get the text area values
  tmpArray = GetRegistryMULTISZ( _
    strWebClientKeyPath,"AuthForwardServerList")For tmpCount = 0 To UBound(tmpArray)
    tmpString = tmpString & tmpArray(tmpCount) & vbTabNextIf Len(tmpString)>0 Then
    Document.all.AuthForwardServerList.Value = _
      Replace(Left(tmpString,Len(tmpString)-1),vbTab,vbCrLf)EndIf
  blnHasChanges = FalseEndSub' ----------------------------------------' Save the settings in the registry.' ----------------------------------------Sub SetValues()OnErrorResumeNext' Set the radio button valuesCall SetRegistryDWORD( _
    strWebClientKeyPath, _"BasicAuthLevel", _
    GetRadioValue(Document.all.BasicAuthLevel))Call SetRegistryDWORD( _
    strWebClientKeyPath, _"SupportLocking", _
    GetRadioValue(Document.all.SupportLocking))' Set the text box valuesCall SetRegistryDWORD( _
    strWebClientKeyPath, _"InternetServerTimeoutInSec", _
    Document.all.InternetServerTimeoutInSec.Value)Call SetRegistryDWORD( _
    strWebClientKeyPath, _"FileAttributesLimitInBytes", _
    Document.all.FileAttributesLimitInBytes.Value)Call SetRegistryDWORD( _
    strWebClientKeyPath, _"FileSizeLimitInBytes", _
    Document.all.FileSizeLimitInBytes.Value)Call SetRegistryDWORD( _
    strWebClientKeyPath, _"LocalServerTimeoutInSec", _
    Document.all.LocalServerTimeoutInSec.Value)Call SetRegistryDWORD( _
    strWebClientKeyPath, _"SendReceiveTimeoutInSec", _
    Document.all.SendReceiveTimeoutInSec.Value)Call SetRegistryDWORD( _
    strWebClientKeyPath, _"ServerNotFoundCacheLifeTimeInSec", _
    Document.all.ServerNotFoundCacheLifeTimeInSec.Value)' Set the text area valuesCall SetRegistryMULTISZ( _
    strWebClientKeyPath, _"AuthForwardServerList", _
    Split(Document.all.AuthForwardServerList.Value,vbCrLf))' Prompt to restart the WebClient serviceIf MsgBox("Do you want to restart the WebDAV Redirector "& _"service so your settings will take effect?", _
    vbQuestion Or vbYesNo Or vbDefaultButton2, _"Restart WebDAV Redirector") = vbYes Then' Restart the WebClient service.Call RestartWebClient()EndIfCall GetValues()EndSub' ----------------------------------------' Start the WebClient service.' ----------------------------------------Sub RestartWebClient()OnErrorResumeNextDim objWMIService,colServices,objService
  Document.All.TheBody.ClassName = "hide"Set objWMIService = GetObject( _"winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")Set colServices = objWMIService.ExecQuery( _"Select * from Win32_Service Where Name='WebClient'")ForEach objService in colServices
    objService.StopService()
    objService.StartService()Next
  Document.All.TheBody.ClassName = "show"EndSub' ----------------------------------------' Retrieve a DWORD value from the registry.' ----------------------------------------Function GetRegistryDWORD( _ByVal tmpKeyPath, _ByVal tmpValueName, _ByVal tmpDefaultValue)OnErrorResumeNextDim tmpDwordValueIf objRegistry.GetDWORDValue( _
      HKEY_LOCAL_MACHINE, _
      tmpKeyPath, _
      tmpValueName, _
      tmpDwordValue)=0 Then
    GetRegistryDWORD = CLng(tmpDwordValue)Else
    GetRegistryDWORD = CLng(tmpDefaultValue)EndIfEndFunction' ----------------------------------------' Set a DWORD value in the registry.' ----------------------------------------Sub SetRegistryDWORD( _ByVal tmpKeyPath, _ByVal tmpValueName, _ByVal tmpDwordValue)OnErrorResumeNextCall objRegistry.SetDWORDValue( _
    HKEY_LOCAL_MACHINE, _
    tmpKeyPath, _
    tmpValueName, _CLng(tmpDwordValue))EndSub' ----------------------------------------' Retrieve a MULTISZ value from the registry.' ----------------------------------------Function GetRegistryMULTISZ( _ByVal tmpKeyPath, _ByVal tmpValueName)OnErrorResumeNextDim tmpMultiSzValueIf objRegistry.GetMultiStringValue( _
      HKEY_LOCAL_MACHINE, _
      tmpKeyPath, _
      tmpValueName, _
      tmpMultiSzValue)=0 Then
    GetRegistryMULTISZ = tmpMultiSzValueElse
    GetRegistryMULTISZ = Array()EndIfEndFunction' ----------------------------------------' Set a MULTISZ value in the registry.' ----------------------------------------Sub SetRegistryMULTISZ( _ByVal tmpKeyPath, _ByVal tmpValueName, _ByVal tmpMultiSzValue)OnErrorResumeNextCall objRegistry.SetMultiStringValue( _
    HKEY_LOCAL_MACHINE, _
    tmpKeyPath, _
    tmpValueName, _
    tmpMultiSzValue)EndSub' ----------------------------------------' Retrieve the value of a radio button group.' ----------------------------------------Function GetRadioValue(ByVal tmpRadio)OnErrorResumeNextDim tmpCountFor tmpCount = 0 To (tmpRadio.Length-1)If tmpRadio(tmpCount).Checked Then
      GetRadioValue = CLng(tmpRadio(tmpCount).Value)ExitForEndIfNextEndFunction' ----------------------------------------' Set the value for a radio button group.' ----------------------------------------Sub SetRadioValue(ByVal tmpRadio, ByVal tmpValue)OnErrorResumeNextDim tmpCountFor tmpCount = 0 To (tmpRadio.Length-1)IfCLng(tmpRadio(tmpCount).Value) = CLng(tmpValue) Then
      tmpRadio(tmpCount).Checked = TrueExitForEndIfNextEndSub' ----------------------------------------'' ----------------------------------------Sub Validate(tmpField)Dim tmpRegEx, tmpMatchesSet tmpRegEx = New RegExp
  tmpRegEx.Pattern = "[0-9]"
  tmpRegEx.IgnoreCase = True
  tmpRegEx.Global = TrueSet tmpMatches = tmpRegEx.Execute(tmpField.Value)If tmpMatches.Count = Len(CStr(tmpField.Value)) ThenIfCDbl(tmpField.Value) => 0 And _CDbl(tmpField.Value) =< 4294967295 ThenExitSubEndIfEndIf
  MsgBox "Please enter a whole number between 0 and 4294967295.", _
    vbCritical, "Validation Error"
  tmpField.FocusEndSub' ----------------------------------------'' ----------------------------------------Sub BasicAuthWarning()
  MsgBox "WARNING:"& vbCrLf  & vbCrLf & _"Using Basic Authentication over non-SSL connections can cause "& _"serious security issues. Usernames and passwords are transmitted "& _"in clear text, therefore the use of Basic Authentication with "& _"WebDAV is disabled by default for non-SSL connections. That "& _"being said, this setting can override the default behavior for "& _"Basic Authentication, but it is strongly discouraged.", _
    vbCritical, "Basic Authentication Warning"EndSub' ----------------------------------------' End of main code section.' ----------------------------------------</script><style>
body { color:#000000; background-color:#cccccc;
  font-family:'Segoe UI',Tahoma,Verdana,Arial; font-size:9pt; }
fieldset { padding:10px; width:640px; }
.button { width:150px; }
.textbox { width:200px; height:22px; text-align:right; }
.textarea { width:300px; height:50px; text-align:left; }
.radio { margin-left:-5px; margin-top: -2px; }
.hide { display:none; }
.show { display:block; }
select { width:300px; text-align:left; }
table { border-collapse:collapse; empty-cells:hide; }
h1 { font-size:14pt; }
th { font-size:9pt; text-align:left; vertical-align:top; padding:2px; }
td { font-size:9pt; text-align:left; vertical-align:top; padding:2px; }
big { font-size:11pt; }
small { font-size:8pt; }</style></head><bodyid="TheBody"class="hide"><h1align="center"id="TheTitle"style="margin-bottom:-20px;">WebDAV Redirector Settings</h1><divalign="center"><pstyle="margin-bottom:-20px;"><i><small><b>Note</b>: See <atarget="_blank"href="http://go.microsoft.com/fwlink/?LinkId=324291">Using the WebDAV Redirector</a> for additional details.</small></i></p><form><center><tableborder="0"cellpadding="2"cellspacing="2"style="width:600px;"><tr><tdstyle="width:600px;text-align:left"><fieldsettitle="Security Settings"><legend>&nbsp;<b>Security Settings</b>&nbsp;</legend>
        These values affect the security behavior for the WebDAV Redirector.<br><tablestyle="width:600px;"><trtitle="Specifies whether the WebDAV Redirector can use Basic Authentication to communicate with a server."><tdstyle="width:300px"><tableborder="0"><tr><tdstyle="width:300px"><b>Basic Authentication Level</b></td></tr><tr><tdstyle="width:300px;"><spanstyle="width:280px;padding-left:20px;"><small><i><b>Note</b>: Using basic authentication can cause <u>serious security issues</u> as the username and password are transmitted in clear text, therefore the use of basic authentication over WebDAV is disabled by default unless the connection is using SSL.</i></small></span></td></tr></table></td><tdstyle="width:300px"><tablestyle="width:300px"><tr><tdstyle="width:020px"><inputclass="radio"type="radio"value="0"name="BasicAuthLevel"onchange="VBScript:FlagChanges()"id="BasicAuthLevel0"></td><tdstyle="width:280px"><labelfor="BasicAuthLevel0">Basic Authentication is disabled</label></td></tr><tr><tdstyle="width:020px"><inputclass="radio"type="radio"value="1"checkedname="BasicAuthLevel"onchange="VBScript:FlagChanges()"id="BasicAuthLevel1"></td><tdstyle="width:280px"><labelfor="BasicAuthLevel1">Basic Authentication is enabled for SSL web sites only</label></td></tr><tr><tdstyle="width:020px"><inputclass="radio"type="radio"value="2"name="BasicAuthLevel"onchange="VBScript:FlagChanges()"id="BasicAuthLevel2"onClick="VBScript:BasicAuthWarning()"></td><tdstyle="width:280px"><labelfor="BasicAuthLevel2">Basic Authentication is enabled for SSL and non-SSL web sites</label></td></tr></table></td></tr><trtitle="Specifies a list of local URLs for forwarding credentials that bypasses any proxy settings. (Note: This requires Windows Vista SP1 or later.)"><tdstyle="width:300px"><tableborder="0"><tr><tdstyle="width:300px"><b>Authentication Forwarding Server List</b></td></tr><tr><tdstyle="width:300px;"><spanstyle="width:280px;padding-left:20px;"><small><i><b>Note</b>: Include one server name per line.</i></small></span></td></tr></table></td><tdstyle="width:300px"><textareaclass="textarea"name="AuthForwardServerList"onchange="VBScript:FlagChanges()"></textarea></td></tr><trtitle="Specifies whether the WebDAV Redirector supports locking."><tdstyle="width:300px"><b>Support for WebDAV Locking</b></td><tdstyle="width:300px"><tablestyle="width:300px"><tr><tdstyle="width:020px"><inputclass="radio"type="radio"value="1"checkedname="SupportLocking"onchange="VBScript:FlagChanges()"id="SupportLocking1"></td><tdstyle="width:280px"><labelfor="SupportLocking1">Enable Lock Support</label></td></tr><tr><tdstyle="width:020px"><inputclass="radio"type="radio"value="0"name="SupportLocking"onchange="VBScript:FlagChanges()"id="SupportLocking0"></td><tdstyle="width:280px"><labelfor="SupportLocking0">Disable Lock Support</label></td></tr></table></td></tr></table></fieldset></td></tr><tr><tdstyle="width:600px;text-align:left"><fieldsettitle="Time-outs"><legend>&nbsp;<b>Time-outs and Maximum Sizes</b>&nbsp;</legend>
        These values affect the behavior for WebDAV Client/Server operations.<br><tableborder="0"style="width:600px;"><trtitle="Specifies the connection time-out for the WebDAV Redirector uses when communicating with non-local WebDAV servers."><tdstyle="width:300px"><b>Internet Server Time-out</b><small>(In Seconds)</small></td><tdstyle="width:300px"><inputclass="textbox"type="text"name="InternetServerTimeoutInSec"onchange="VBScript:FlagChanges()"onblur="VBScript:Validate(Me)"value="30"></td></tr><trtitle="Specifies the connection time-out for the WebDAV Redirector uses when communicating with a local WebDAV server."><tdstyle="width:300px"><b>Local Server Time-out</b><small>(In Seconds)</small></td><tdstyle="width:300px"><inputclass="textbox"type="text"name="LocalServerTimeoutInSec"onchange="VBScript:FlagChanges()"onblur="VBScript:Validate(Me)"value="15"></td></tr><trtitle="Specifies the time-out in seconds that the WebDAV Redirector uses after issuing a request."><tdstyle="width:300px"><b>Send/Receive Time-out</b><small>(In Seconds)</small></td><tdstyle="width:300px"><inputclass="textbox"type="text"name="SendReceiveTimeoutInSec"onchange="VBScript:FlagChanges()"onblur="VBScript:Validate(Me)"value="60"></td></tr><trtitle="Specifies the period of time that a server is cached as non-WebDAV by the WebDAV Redirector. If a server is found in this list, a fail is returned immediately without attempting to contact the server."><tdstyle="width:300px"><b>Server Not Found Cache Time-out</b><small>(In Seconds)</small></td><tdstyle="width:300px"><inputclass="textbox"type="text"name="ServerNotFoundCacheLifeTimeInSec"onchange="VBScript:FlagChanges()"onblur="VBScript:Validate(Me)"value="60"></td></tr><trtitle="Specifies the maximum size in bytes that the WebDAV Redirector allows for file transfers."><tdstyle="width:300px"><b>Maximum File Size</b><small>(In Bytes)</small></td><tdstyle="width:300px"><inputclass="textbox"type="text"name="FileSizeLimitInBytes"onchange="VBScript:FlagChanges()"onblur="VBScript:Validate(Me)"value="50000000"></td></tr><trtitle="Specifies the maximum size that is allowed by the WebDAV Redirector for all properties on a specific collection."><tdstyle="width:300px"><b>Maximum Attributes Size</b><small>(In Bytes)</small></td><tdstyle="width:300px"><inputclass="textbox"type="text"name="FileAttributesLimitInBytes"onchange="VBScript:FlagChanges()"onblur="VBScript:Validate(Me)"value="1000000"></td></tr></table></fieldset></td></tr><tr><tdstyle="text-align:center"><tableborder="0"><tr><tdstyle="text-align:center"><inputclass="button"type="button"value="Apply Settings"onclick="VBScript:SetValues()"><tdstyle="text-align:center"><inputclass="button"type="button"value="Reset Values"onclick="VBScript:ResetApplication()"><tdstyle="text-align:center"><inputclass="button"type="button"value="Exit Application"onclick="VBScript:ExitApplication()"></tr></table></td></tr></table></center></form></div></body></html>
Additional Notes

As with the last version of this HTML Application, you will need to run this application as an administrator in order to save the settings to the registry and restart the WebDAV Redirector service.

Have fun! ;-]


Viewing all articles
Browse latest Browse all 29128

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>