vbscript FileSystemObject works locally but not live - vbscript

can anyone tell me what's going on with this (what should be) simple peice of VBscript. It is working locally but as soon as I try it online, it kick out an error as below! Everythings saved in the root!
Any ideas appreciated! I'm starting to pull my hair out!
<%
'path = filesys.GetAbsolutePathName("c:/inetpub/wwwroot/website/somefile.txt")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile (server.MapPath("/somefile.txt"), 8, True)
filetxt.WriteLine("Last Update: ") & Now
filetxt.Close
%>
I keep getting the following error...
Microsoft VBScript runtime error '800a0046'
Permission denied
/locations.asp, line 6

Error description is clear. You need write access to the directory which you want. If you're a hosting customer, you should grant write permission to the IUSR account in your control panel. Usually, username similar to IUSR_sitename.com. So If it all gets too confusing, perhaps you should open a ticket in your provider's helpdesk.

Related

saving file with download prompt with vbscript

I'm using VBscript to use IE to open a webpage - login - and save some data to a file.
Why use IE?
- I can use VBScript to interact with the webpage
- The webpage uses ajax to do verification and signing in, so simply using MSXML2.XMLHTTP wont work.
After IE log into the site, I direct it to the page I want to save as a file, the problem is this page is returning JSON data (filename.json) - so IE is prompting to open/save/saveas rather than just opening the page, so I cant save the data of the page.
The code is below. Any help is much appreciated.
Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
IE.Visible = True
IE.Navigate "https://www.somesite.com"
Wait IE
With IE.Document
.getElementByID("username").value = "myusername"
.getElementByID("password").value = "mysecret"
.getElementsByName("Login")(0).Click
End With
Wait IE
'# all fine here, logged in and redirected to members page
IE.Navigate "https://www.somesite.com/api/data"
' # this link returns json data
'# this is where everything stops because Im getting a download/save as prompt in IE
EDIT: ok, I was able to get IE to display the content rather than downloading it by editing the registry to treat .json file as text files,Now the problem is the page is a json file, not a HTML file, so I cant get it's content by calling IE.Document.Body.InnerHTML like normal HTML pages.
How would I get the content of the page and assign it to a variable so I can process it?
oh, I just put this in my code:
Set objShell = CreateObject("WScript.Shell")
objShell.RegWrite "HKEY_CLASSES_ROOT\.json\Content Type", "text/plain", "REG_SZ
That way the file is treated as a textfile within IE and it will just open in the page. Then I can use the normal objIE.Document.Body.InnerText to get the json contents. Then I pass that variable onto my function that decodes it all.
Hope this helps someone, because all the results on google I found did not help me. Only reason I posting on this old thread!
Cheers,
Ross

VB6: Automation error The remote procedure call failed

In my VB6 application sometimes in some customer PC we get error like
Automation error
The remote procedure call failed.
The error comes for the code shown below
Dim WithEvents Web_popup As SHDocVw.InternetExplorer
Set Web_popup = Nothing
Set Web_popup = New SHDocVw.InternetExplorer
Set ppDisp = Web_popup.Application
Also for the below code
Dim iE As New SHDocVw.InternetExplorer iE.Navigate "www.example.com", 4 + 8
iE.Visible = True
What may be the reason for these errors? How to solve it?
You should include more information when asking for help. More importantly, you should point exactly which lines are causing the error. That being said, it sounds to me that you are not checking the ready state of the download of html to Explorer. Interacting with a web page before the web page has been completely download will cause this symptom.
If you are checking the ready state, the only other way I was able to produce the error was turning on protected mode in Internet Explorer. Some websites cause the error when Protected mode is on.

WIndows file/ folder permission using vb.net

I can set file/ folder restriction using the given code.
Imports System.Security.AccessControl
Dim FolderPath As String = "C:\TestingFolder" 'Specify the folder here
Dim UserAccount As String = "MYDOMAIN\someuser" 'Specify the user here
Dim FolderInfo As IO.DirectoryInfo = New IO.DirectoryInfo(FolderPath)
Dim FolderAcl As New DirectorySecurity
FolderAcl.AddAccessRule(New FileSystemAccessRule(UserAccount, FileSystemRights.Modify, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow))
FolderAcl.SetAccessRuleProtection(True, False) 'uncomment to remove existing permissions
FolderInfo.SetAccessControl(FolderAcl)
My aim is to set the permission using the code in a way that only my application can change the read/write access to the file/folder. No one can change the permission except my vb.net program.
My goal is to write a security application which will ask password to access the program, and the program will be able to grant access(read/write/modify) to the user.

What default credential Directory Entry binds to if it is running as a service on Windows

If I bind to a DirectoryEntry ( without any arguments) on the application mode to search all the users at my current domain, I could see the logged in in user is the default credential for DirectoryEntry since it finds all the users for my domain. With that, I would expect that this won't work if the application is run at service mode since account for service is SYSTEM which is not a user of my domain. However the code still works and it could get all the users of my logged in user domain.
I did some search on internet, I didn't find any answer on this when running as a service. Any idea? Any way I could get that default credential at power shell?
At service mode, the default credential for directory entry would be the credential which computer is used to login into the domain (called computer login). See this link: https://serverfault.com/questions/61191/what-happens-when-a-computer-joins-an-active-directory-domain.
I first tried to use System.Net.CredentialCache::DefaultNetworkCredentials
to try to get the default credential, however I found out the user and domain are all blank. It is confirmed from MSDN that we could not view those info with the returned NetworkCredentials.
So I added the following vb script (got the base code from this link: http://blogs.technet.com/b/heyscriptingguy/archive/2008/05/12/how-can-i-determine-the-distinguished-name-of-the-ou-where-the-logged-on-user-s-user-account-resides.aspx) to be called from power shell to get the dn of the current user
and save it to a file.
Set objSysInfo = CreateObject("ADSystemInfo")
strUserName = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUserName)
Wscript.Echo objUser.distinguishedName
Set objFS = CreateObject("Scripting.FileSystemObject")
strTemp = "c:\temp\dn.txt"
Set objOutFile = objFS.CreateTextFile(strTemp,True)
objOutFile.Write(objUser.distinguishedName)
objOutFile.Close
Then when I ran it in service context, I found out that user is my computer itself, like this:
CN=my computer name,OU=Domain computer accounts,DC=domain,DC=local

Whats the best way to Programmatically Process New Email Messages and Store Attachments

I have several clients/vendors that distribute reports to me via email. Some of these files are enormous, and need to be removed from email and saved on a file share for processing, as well as to control mailbox size.
Can anyone provide guidance on their recommended method of automatically downloading and saving attachments.
I am in a MS Windows Environment (Client & Server Computers). Emails are on an Microsoft Exchange 2003 Email Server.
Preferred use of Microsoft Technology for consistency across solutions (C#), however I am open to any suggestions, be it C#, VBScript, Perl, Java, Components I should purchase, etc..
Scenario
Each Day bob#whysendmereportsbyemail.com sends an email with the subject "Activity Report for YYYY-MM-DD" to me at
john#myemailaddress.com
Each Email has an attachment named "ActivityReport-YYYY-MM-DD-HH-MI-SS.xls" which I need to save on my filesystem at
"C:\FilesFromBob\ActivityReport-YYYY-MM-DD-HH-MI-SS.xls"
Thanks in advance for any assistance.
Exchange 2003 provides a WebDav API which you can use to access emails, contacts etc.. from a user's account.
There's a few answers about accessing a user's Exchange inbox on SO already. I've previously used this approach for almost exactly the situation you outline, and once you work out the WebDav API model and the structure of the requests and responses, it's not too difficult to extract emails and their attachments.
There are other ways to interact with Exchange 2003 (outlined on SO here), but I've only tried the WebDav approach because it seemed the most reliable.
I finally wrote the code to store messages from Outlook
Unfortunately this code runs from within Outlook, so Outlook has to be open.
I did not yet investigate how to schedule the run, but now its easy to do
Sub SaveOutlookFileAttachments()
Dim oStores As Outlook.Stores
Dim oStore As Outlook.Store
Dim oFolders As Outlook.Folders
Dim oFolder As Outlook.Folder
Dim destFolder As String
Dim oItems As Outlook.Items
Dim oMsg As Outlook.MailItem
Dim oAttachments As Outlook.Attachments
Dim oAttachment As Outlook.Attachment
Dim oExplorer As Outlook.Explorer
destFolder = "\\NetworkShare\OrderDetailReport\"
On Error Resume Next
Set oStores = Application.Session.Stores
For Each oStore In oStores
If oStore.DisplayName = "Inbox" Then
oFolders = oStore.GetSearchFolders
For Each oFolder In oFolders
oItems = oFolder.Items
For Each oMsg In oItems
oAttachments = oMsg.Attachments
For Each oAttachment In oAttachments
If InStr(1, oAttachment.FileName, "orderdetail_", vbTextCompare) Then
'MsgBox ("This File Needs to be Saved: " & oAttachment.FileName)
oAttachment.SaveAsFile (destFolder & oAtch.DisplayName)
End If
Next
Next
Next
End If
Next
End Sub

Resources