Scheduled Agent Tricks: Log in to a restricted file share with alternate username/password
Category Show-n-Tell Thursday SnTT Lotus Domino
So the SQL Server guy stops
by and says, "Hey, we want to create some reports of Notes data and
we only know how to use SQL Server to do it. Do you mind exporting it to
a delimited text file and saving it to this restricted folder on the file
server? Here's the username and password of a special Windows account with
rights to the folder. Oh, and we need it to run on a scheduled basis so
everything is automated. Thanks!"
So I think, "Gee, dumping Notes data to a text file...piece of cake. Saving that file somewhere...yeah whatever. Run the export on a schedule...no problem since Domino has scheduled agents. Save the file to a *restricted* folder on the file server...with a different set of credentials...uh, I don't think so."
At this point I figure we just need to give the Windows machine on which the Domino server resides access to said restricted directory, since after all it is the server doing the work. I've never considered the need to output a file somewhere that wasn't semi-open, so the notion of telling a Domino agent to "please use this username/password" when it runs didn't seem promising. But as with any question I cannot answer definitively, I try to find someone who can. And considering this is a question of Domino interacting with the Windows environment, who else to check with but our own Code Poet in Residency, Charles Robinson.
So I say, "Charles, here's what these guys want me to do. I think it might be a non-starter, but figured you'd know (way) better than I. Any thoughts?" And sure enough, Charles shoots back a couple of links to some sample code that puts me on what I hope is the right path.
The second link is what got me going, and after some fiddling to get the VB code ported over to work in LotusScript, presto!
So, without further ado, I present a little script library containing a couple of routines that will allow you to open and close a remote connection to a restricted file folder. You should be able to do whatever you want in terms of reading, updating, and saving files to that folder once you open the connection. I've included two sample agents to help get you started. One uses simple Print statements to write out a text file (as was my case), and the other detaches files from Notes documents to the folder.
Enjoy!
Download from OpenNTF here
So the SQL Server guy stops
by and says, "Hey, we want to create some reports of Notes data and
we only know how to use SQL Server to do it. Do you mind exporting it to
a delimited text file and saving it to this restricted folder on the file
server? Here's the username and password of a special Windows account with
rights to the folder. Oh, and we need it to run on a scheduled basis so
everything is automated. Thanks!"
So I think, "Gee, dumping Notes data to a text file...piece of cake. Saving that file somewhere...yeah whatever. Run the export on a schedule...no problem since Domino has scheduled agents. Save the file to a *restricted* folder on the file server...with a different set of credentials...uh, I don't think so."
At this point I figure we just need to give the Windows machine on which the Domino server resides access to said restricted directory, since after all it is the server doing the work. I've never considered the need to output a file somewhere that wasn't semi-open, so the notion of telling a Domino agent to "please use this username/password" when it runs didn't seem promising. But as with any question I cannot answer definitively, I try to find someone who can. And considering this is a question of Domino interacting with the Windows environment, who else to check with but our own Code Poet in Residency, Charles Robinson.
So I say, "Charles, here's what these guys want me to do. I think it might be a non-starter, but figured you'd know (way) better than I. Any thoughts?" And sure enough, Charles shoots back a couple of links to some sample code that puts me on what I hope is the right path.
Connecting to a remote share with different credentials really isn't that difficult: http://vbnet.mvps.org/index.html?code/network/wnetaddconnection2.htm or http://www.dreamincode.net/forums/showtopic34399.htm. The issue is what rights the account running Domino has to the local system. You may end up having to create a new account for Domino to run under, but that would be the only configuration change in the worst case scenario.
The second link is what got me going, and after some fiddling to get the VB code ported over to work in LotusScript, presto!
So, without further ado, I present a little script library containing a couple of routines that will allow you to open and close a remote connection to a restricted file folder. You should be able to do whatever you want in terms of reading, updating, and saving files to that folder once you open the connection. I've included two sample agents to help get you started. One uses simple Print statements to write out a text file (as was my case), and the other detaches files from Notes documents to the folder.
Enjoy!
Download from OpenNTF here


- 


Comments
Posted by Todd Kravos At 01:00:51 PM On 05/30/2008 | - Website - |
Posted by Kevin Pettitt At 01:13:15 PM On 05/30/2008 | - Website - |
I'll take a look at this code. It could well come in handy at some point. Did you consider using the Lotus Notes ODBC client (on the SQL server) and pull the Domino data directly without going via a text file?
See you in Dublin!
Rob
Posted by Rob Wills At 01:41:52 PM On 06/01/2008 | - Website - |
Posted by Kevin Pettitt At 02:39:46 PM On 06/01/2008 | - Website - |
This is very timely. I'm in the middle of the same thing. I've done this before by creating a .bat file on the server that does an xcopy with the id and password in the path. I run one LEI job to create the file to the Notes server and then run another shell agent to run the .bat. I really like your solution and will give it a try.
THANKS! Notes.net reading told me this could not be done because the server runs as a service and the service has no access to mapped drives on the server.
Posted by Curt Stone At 10:27:24 AM On 06/02/2008 | - Website - |
I was looking at your code and like I was saying, I was playing around with this recently too. Instead of hard coding the column titles, I created the view columns to match the target and did this to add to the first row of the exported text file.
Forall c In view.Columns
item = c.Title
szOut = item
Print #1, szOut & |;|;
End Forall
Print #1, "" ' End the line
szOut and item are strings. Took me a while to find the Title property.
Posted by Curt Stone At 10:35:55 AM On 06/02/2008 | - Website - |
Played around some more. Instead of a search query, I'm looping through a view and using the view column values. This way, I was able to use column formulas in my views to do some of the string replacement for commas and @Newline. Cool. Very nice. Thank you. I just did it to my local. Will try on server too.
Posted by Curt Stone At 12:11:08 PM On 06/02/2008 | - Website - |
I would be curious to know if anyone encounters problems running on the server. There may yet prove to be some network configurations/partitioning where it won't work.
Posted by Kevin Pettitt At 12:24:01 PM On 06/02/2008 | - Website - |
Understood.
I imagine since it's using Win32 api, it breaks when the os changes. But, doesn't everything involving MS break when the os changes? :)
Posted by Curt Stone At 01:18:01 PM On 06/02/2008 | - Website - |
Posted by Jim Roysdon At 01:19:01 PM On 06/02/2008 | - Website - |
Posted by null At 02:19:16 AM On 07/08/2008 | - Website - |