I have been given a script that will open a connection to a remote server using its static IP address, I can connect and open a document, edit and do what I need to... btw this is the company hot potato and as I am the new lad...
The problem is on some PC's the documents open as read only despite being asked for credentials in word and the fact I am being asked for the credentials a second time by word after using the map network drive function call with the same credentials.
I have noticed that when using a SharePoint object to open the document it creates an unlettered mapped drive that it keeps open after the word document closes, while this is open the documents can be edited if using the hta method; whcih leads me to believe that the hta cannot connect correctly to the server without the unlettered network drive already being open.
The server that the documents are on uses SabreDAV so I would have thought that opening the network drive would have done this, or is there a way of authentication that I am missing out?
it checks if the hta is open in order to gain access the word document and use the editor script which adds custom tags and , if it is not open it uses SharePoint to still allow editing but without access to the tags.
From what I can work out creating the unlettered networked drive is failing then because the original catch in script did not do anything and because of the SharePoint object connection workaround it has gone unfixed until I began at the company...
This is the script can anyone see what is wrong?
Underneath that is a HTA script that works 100% each time and can see that it should be doing exactly the same thing.
The difference being that the hta directly calls the functions (on the client) whereas the top script calls from a web page
could that be the issue? using the web based script the mapped drive is created on the server not the client?
(oh apart from ones in VB and the other JS :) )
The problem is on some PC's the documents open as read only despite being asked for credentials in word and the fact I am being asked for the credentials a second time by word after using the map network drive function call with the same credentials.
I have noticed that when using a SharePoint object to open the document it creates an unlettered mapped drive that it keeps open after the word document closes, while this is open the documents can be edited if using the hta method; whcih leads me to believe that the hta cannot connect correctly to the server without the unlettered network drive already being open.
The server that the documents are on uses SabreDAV so I would have thought that opening the network drive would have done this, or is there a way of authentication that I am missing out?
it checks if the hta is open in order to gain access the word document and use the editor script which adds custom tags and , if it is not open it uses SharePoint to still allow editing but without access to the tags.
From what I can work out creating the unlettered networked drive is failing then because the original catch in script did not do anything and because of the SharePoint object connection workaround it has gone unfixed until I began at the company...
This is the script can anyone see what is wrong?
Underneath that is a HTA script that works 100% each time and can see that it should be doing exactly the same thing.
The difference being that the hta directly calls the functions (on the client) whereas the top script calls from a web page
could that be the issue? using the web based script the mapped drive is created on the server not the client?
(oh apart from ones in VB and the other JS :) )
Code:
if (window.top.htaFile)
{ // Open directly
try {
window.top.wordApp.Visible = true;
} catch (e) {
window.top.wordApp = new ActiveXObject("Word.application");
}
window.top.wordApp.Visible = true;
// On vista we need to be sure the machine is connected to webdav first.
// You can see if this is active by typing "net use" in cmd.
try {
var WshNetwork = new ActiveXObject("WScript.Network");
WshNetwork.MapNetworkDrive ("", window.top.currentDocumentsPath, false, window.top.currentUserName+'@'+window.top.currentClientUsername, window.top.currentSecretDav);
} catch(err) {
// what should I do here if the drive fails...?
}
doc = window.top.wordApp.Documents.Open(url);
// Bring word doc to front
if (!('wshShell' in window.top)) {
window.top.wshShell = new ActiveXObject("WScript.Shell");
}
window.top.wshShell.SendKeys("%{TAB}"); // Send alt-tab - it seems to help.
doc.windows.Item(1).Activate();
doc.windows.Item(1).WindowState = 1; //wdWindowStateMaximize
window.top.wshShell.AppActivate(doc.windows.Item(1).caption);
return doc;
}
else
{ // Open with Sharepoint activeX stuff
try
{
doc = new ActiveXObject("SharePoint.OpenDocuments.3");
}
catch (e)
{
try
{
doc = new ActiveXObject("SharePoint.OpenDocuments.2");
}
catch (e)
{
try
{
doc = new ActiveXObject("SharePoint.OpenDocuments.1");
}
catch (e)
{
window.location=url;
}
}
}
if (doc)
{
doc.EditDocument(url, 'Word.Document');
return doc;
}
else{
//in case of FF, Chrome etc
alert("This will open as read only'");
}
}
}Code:
<HTML>
<head><title>Get Drive</Title>
<HTA:APPLICATION id="jupix"
applicationName="Jupix"
icon="https://login.jupix.co.uk/images/favicon.ico"
maximizeButton="yes"
minimizeButton="yes"
showInTaskbar="yes"
windowState="normal"
innerBorder="yes"
navigable="yes"
scroll="no"
singleInstance="yes"
sysMenu="yes"
contextMenu="yes"
selection="yes"
version="1.0" />
</Head>
<Script Language="VBSCRIPT" Type = "text/vbscript">
Sub Window_Onload
Window.resizeTo 475,400
End Sub
'### This script is for mapping drives when at home VPNed to the office.
Sub CloseWindow
self.close
End Sub
FUNCTION MapDrives(uName, pWord)
'### Build Account Details
aName = uName.value
aWord = pWord.value
'### Build Home Drive Path
xD = ""
'### Sets the path to the home drive where the username is the hidden share
sName = "\\servername\folder\toDocuments"
'### Map Drives
Set objNet = CreateObject("Wscript.Network")
objNet.MapNetworkDrive xD, sName, , aName, aWord
'### TL's open doc (but using server value not HTTP)
OpenDoc(sName & "\wordDocumentName.doc")
END FUNCTION
Sub OpenDoc(strLocation)
Set objWord = CreateObject("Word.Application")
objWord.Visible = true
objWord.Documents.Open strLocation
End Sub
</Script>
<body>
<Table>
<TR><td>Enter Your Username: </td><td><input type="text" name="uName"></td></TR>
<TR><td>Enter Your Password: </td><td><input type="PASSWORD" name="pWord"></td><TR>
<TR><td><input type="BUTTON" value="Open Document" onclick="MapDrives uName, pWord"></td><TR>
<TR><td><input type="BUTTON" value="Quit" onclick="CloseWindow"></td><TR>
<TR></TR>
</Table>
<Table>
<TR><td><textarea name="DispDrives" rows="12" cols=45></textarea></td></tr>
</Table>
</body>
</html>