PDA

View Full Version : file.open not working


wasim21k
04-24-2007, 06:11 AM
hi guys.
i have script on click and trying to open hosts file from this location.

File.Open("C:\\WINXP\\system32\\drivers\\etc\\hosts", "", SW_SHOWNORMAL);

but if i type this address in run c:\WINXP\system32\drivers\etc\hosts windows ask me with open to select some software to open this file (its just text file) so notepad is the best to open it.
can i just simple specify to open this file in notepad?

bule
04-24-2007, 06:38 AM
Try it like this:

File.Run("notepad.exe", "", _SystemFolder.."\\drivers\\etc\\hosts", SW_SHOWNORMAL, false);

wasim21k
04-24-2007, 07:59 AM
no its not working.
File.Run("notepad.exe", "", _SystemFolder.."\\drivers\\etc\\hosts", SW_SHOWNORMAL, false);

i checked hosts file is present.

wasim21k
04-24-2007, 08:07 AM
sorry to bother you but here is i tested it works just have to specify temp working folder.:yes
File.Run("notepad.exe", "c:\\WINXP\\system32\\drivers\\etc\\hosts", "C:\\Temp", SW_SHOWNORMAL, true);

Tek
04-24-2007, 08:30 AM
By default, Windows XP is installed to C:\Windows so if you are going to run this application on other workstations it is best to take advantage of the built in variable '_SystemFolder'. There is also a variable for the users temporary folder called '_TempFolder'.


File.Run("notepad.exe", _SystemFolder.."\\drivers\\etc\\hosts", _TempFolder, SW_SHOWNORMAL, true);

wasim21k
04-24-2007, 08:49 AM
thanks guys for help i was thinking about that but in this case what should i do?
this code is for copy

if e_Key == 13 then

-- get input ip address from user
DestFolder = Input.GetText("Input1");

--progress bar
StatusDlg.Show(MB_ICONNONE, false);

--code to copy file from location to destination
File.Copy("c:\\hosts", DestFolder.."\\C$\\winxp\\system32\\drivers\\etc\\hosts", true, true, false, true, nil);


-- Check to see if the File.Copy action failed by getting it's error code.
error = Application.GetLastError();
StatusDlg.Hide();

-- If it failed (not equal to 0), display a dialog informing the user.
-- If it succeeded, open an explore window showing the "Copied Files" folder.
if error ~= 0 then
result = Dialog.Message("Error", "There was an error copying the files to your system. Please try again.", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);

end

end

for opening host file.

DestFolder = Input.GetText("Input1");
File.Run("notepad.exe", DestFolder.."\\C$\\winxp\\system32\\drivers\\etc\\hosts", "C:\\Temp", SW_SHOWNORMAL, true);


anc apz is attached with this post. can you please have look