|
Hi all,
I have recently been working on a project that requires to open documents that are password protected. I need to give the password at the run time from my application (NOT MANUALLY). I was using shellExecute() to open the file but I cant pass the password at run time. I need to give passwords for each file MANUALLY.
CString cFileName = FileName; //FileName variable storing the filepath
CString cAction = _T("open") ;
ShellExecute(0,cAction,cFileName,NULL,NULL,1);
Please help me in this regard. Is there any inbuilt class in MFC to cater to this issue. Ho can I OPEN the password protected files at run time?
|
|
|
|
|
It's going to depend on the application that's loading it. There is no generic solution.
If it's application you wrote yourself, then you can call CreateProcess and put arguments in the command line. ie:
c:\program files\myapp\myapp.exe /p password c:\mydoc.xyz
If it's office, then I can't find a /password switch - but you can run a macro on loading with the /m switch, so *MAYBE* you could create a macro that would open a file with a given password. But that's a maybe.
Alternatively, you could automate word and drive it that way, but that's outside my expertise.
If it's some other application, I have no idea. Not very psychic today.
Good luck,
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
Hey I am not sure whether this will work. I am very weak with MACROS, so I am opting for some other options that will reduce the MACROs. Will Office Automation be of help in this regard?
|
|
|
|
|
I'm confused - Are you skamaal or salimhassan?
You have gone outside my field of expertise... I just know you can't do it in normal windows-y stuff.
In my last post I suggested investigating Automation, and David Crow also said it's the way to go. I'd take his word for it if I were you...
The articles under http://www.codeproject.com/KB/office/#Office%20Automation[^] may be of help to you. They're aimed at excel, but the approach is probably still valid.
Good luck!
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
Yeah both are me..
actually I logged in with my old ID. Well I have an issue at present that I cannot be using WORD automation as this is increasing the complexity in my program.
basically tried the folloing link
http://support.microsoft.com/kb/252719
The examples at the link you provided are good but I am having a problem with the office versions (most of them are for office 2000 03, I am using 07).
One of the solution i got is that I can capture the Handle of the DIALOG BOX(asking for password) that is opened , and use this handle to pass my password.
I found this link that is similar to my problem. here the handle is being used to close the window.
First the windows are enumerated and then the desired handle is used to close the window.
http://www.tech-archive.net/Archive/VC/microsoft.public.vc.mfc/2006-04/msg01244.html[^]
Could you please suggest whether this approach will work?
|
|
|
|
|
salimhassan wrote: Could you please suggest whether this approach will work?
Well, if you can monitor for the fialog window and use SetWindowText, then that sounds like it would work. But I'd think of that as a very fragile solution - maybe a different language user, or a different version of word, and your solution might fail.
But I know next to nothing about automation other than how to spell it, so I'd probably join you on the hack-the-dialog approach!
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
Hi
I am getting linking errors with the previous code I shared.
1>shell5.obj : error LNK2019: unresolved external symbol _EnumProcesses@12 referenced in function _main
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
Dont know how to proceed further as i am weak in Window Programming..
|
|
|
|
|
If you search MSDN for EnumProcesses, you'll need to add Psapi.lib to your included libraries.
As fro _WinMain, I'm not sure but this sounds like a UNICODE issue. Do a search for "entry point" and "wWinMainCRTStartup", and that will hopefully steer you right.
But if I'm right about the second point, it would mean you've never been able to run your software, so I'm less sure.
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
Hey I was trying with getting the DIALOG Box Handle which comes when I open a password protected word file.
I found that below message is generated for the processess for word and the related dialog box.
"Password" "bosa_sdm_Microsoft Office Word12.0'
"Microsoft Word" 'OpusApp'
I am not sure which one is for what....
I used a tree control to list all the process running and getting the related handle.
::GetWindowText(hwnd, wndtext, sizeof(wndtext)/sizeof(TCHAR));
::GetClassName(hwnd, classname,
sizeof(classname)/sizeof(TCHAR));
str.Format (_T("%08Xh \"%s\" \'%s\' "), hwnd, wndtext,
classname);
getting some poblem with the comparisons..
CString a;
a.Format(_T("%08Xh "),hwnd);
CString temp = _T("\"TF_FloatingLangBar_WndTitle\" 'CiceroUIWndFrame' ");
a.Append(temp);
//if(str.Find(_T("\"Password\" 'bosa_sdm")))
if (!str.Compare(a))
never compares to true for the strings.
|
|
|
|
|
I'm sorry, but you've gone way off any map I have for what you're trying to do.
All I can suggest is lots of debugging, and use of Spy++ to scout out the territory.
Alternatively, David's explanation of automation looks pretty good - and should be more robust also.
Good luck,
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
Yeah After working so hard on this, I finally feel that I need to go for the automation instead of this Hunting Handle for the DIALOG.. Its not a good solution.. Any ways I am having hell lot of problems in that too.
I am facing prob for _Application object. as suggested by David I am trying for that too.
_Application app;
app.CreateDispatch("Word.Application");
Documents docs = app.GetDocuments();
_Document doc = docs.Open(strFile, vtOptional, vtOptional, vtOptional, strPassword,vtOptional, vtOptional, vtOptional, vtOptional,vtOptional, vtOptional, vtOptional);
finally nothing worked as I was stucked with the _Application class.
Got errors
error C2065: '_Application' : undeclared identifier
I selected classes _Application, _Document, Documents, Bookmarks, Bookmark, Range and Selection..
Project->add class->MFC Class From TypeLib->(from available type classes selected the one for the word). then selected the above mentioned classes.
Is thre any other way to do this . I am using Visual Studio 2008 .NET version.
I completely bugged with this as i tied to develop a tool to reduce my burden of opening files, instead its eating hell lot of my time and brain.
|
|
|
|
|
salimhassan wrote: The examples at the link you provided are good but I am having a problem with the office versions (most of them are for office 2000 03, I am using 07).
Things changed with Office 2007 (e.g., creating actual classes from a type library). See the last part of this article for an example of using Excel 2007.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi David,
After breaking my head with this DIALOG Handle stuff, I have finally decided that this is not going to help in any ways. I guess I need to work on COM now, for automation. I am very new to COM and VC++(1 month into my VC++ stuff). So will be bugging you all untill I get the solution for this.
Please If possible suggest some good tutorials for COM , ATL . I am a biginner in this field.
Kamaal
|
|
|
|
|
Are you limited to ShellExecute() , or can you use Office Automation?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
No limitations to ShellExecute(). Can use Office automation too.. Presently trying with that...
kamaal hassan
software engg
|
|
|
|
|
skamaal wrote: I am really not sure of this Office Automation tool.. could you suggst some more details regarding this.
It's not a tool per se. See here.
skamaal wrote: Will it be possible to pass the password through createProcess /p password as suggested in the previous post by one of the forum friend.??
No, unless the application that you are starting can handle such a command-line argument. Office cannot.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Yeah I got to know that once I started to Automate WORD. Any how the Office Automation is out of site as this is adding a lot of code to my application.
I read that some article on how to get the handle to close the window opened through SHELLEXECUTE. SO I thought I can use the same concept to solve my problem.
When I try to open password protected word file through my aplication (ShellExecute(...)), I get a dialog box that asks for the password. So if i could Some how get the Handle for this DIALOG, I could probably pass my password using that HANDLE.
I was trying with some window programming (Very new to this). still not sure how to get the HANDLE. Please could you help in this regard.
|
|
|
|
|
salimhassan wrote: Any how the Office Automation is out of site as this is adding a lot of code to my application.
Not as much as you think.
The question at this point becomes, why are you wanting to open the file?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Its the need of the hour..
Daily I need to Open some 15 - 20 files that are password protected and need to compare them for the changes and start my work accordingly.
So I guess if I can open these files without me typing the password, I can later use some comparison in the same application that will just give a new file with only the changes found in these docs. this will save alot of time.
I can later implement this in office too. (Frankly speaking its purely for my april appraisal )
kamaal
|
|
|
|
|
salimhassan wrote: So I guess if I can open these files without me typing the password...
Which would require about 4-5 lines of code:
_Application app;
app.CreateDispatch("Word.Application");
Documents docs = app.GetDocuments();
_Document doc = docs.Open(strFile, vtOptional, vtOptional, vtOptional, strPassword,
vtOptional, vtOptional, vtOptional, vtOptional,
vtOptional, vtOptional, vtOptional);
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi I tried that one too...
getting error
error C2065: '_Application' : undeclared identifier
I selected classes _Application, _Document, Documents, Bookmarks, Bookmark, Range and Selection..
Project->add class->MFC Class From TypeLib->(from available type classes selected the one for the word). then selected the above mentioned classes.
Even then I am getting the same errors. Dont know how to proceed further.
I guess I need to import some files
#import "mso9.dll" rename("RGB", "MSRGB")
#import "VBE6EXT.OLB" raw_interfaces_only, rename("Reference", "MyReference"), rename("VBE", "testVBE")
#import "msword.olb" rename("ExitWindows", "MyExitWindow"), rename("VBE", "testVBE"), rename("FindText", "WFindText"), rename("NoPrompt", "WNoPrompt")
I am totally confused now... Going ahead witht he Dialog option but same result getting assertion erors at run time...
Guess I need to go on with the manual entering the password...
kamaal
|
|
|
|
|
salimhassan wrote: ...but same result getting assertion erors at run time
What line of what file is asserting?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Sorry, mixed some other issue . Actually that was some debug assertion eror in some other application. that was due to some initialization problem.
I guess I am missing some basic concept fom COM. So going through this as I have started VC++ just a little while ago...
|
|
|
|
|
A Friend function can be avoided if get()(to read) and set()(to write) member functions(public) are provided on (private) data members of a class.
Is it True or False.
Can anyone help me clearing this doubt with an appropriate reason?
|
|
|
|
|
The friend keyword allows you to specify functions or other classes which will be able to access all member (public, protected or private) of the class in which the friend keyword is used. Thus one way to avoid using it would be to provide getters and setters. But this is not always a good approach because all your members will become 'visible' to everybody, which is not always what you want.
|
|
|
|