I came across a small hack, which claims it enables smb:// on windows.
The complaint was that things like text weren't working.
While true that you can use file:///// in your url's, the user wanted to use smb:// so that it's cross-platform.
The hack goes as follows:
1) Create this Reg file, save and execute it:
REGEDIT4
[HKEY_CLASSES_ROOT\smb]
#="URL:smb Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\smb\shell]
[HKEY_CLASSES_ROOT\smb\shell\open]
[HKEY_CLASSES_ROOT\smb\shell\open\command]
#="\"C:\\smb.bat\" \"%1\""
And then create the smb.bat file in your C-folder, containing this:
#echo off
cd C:\
set url=%~dpnx1
explorer \%url:~7%
exit
My question: how safe is this, and any other thoughts on the matter? Besides the file:///// thing I mean.
To me, it looks damn dangerous because it allows any website to place "\\RESOURCENAME" URLs, which will work regardless of context, and smb.bat will be called if you click such a link. I don't entirely understand the batch syntax (the ~ part especially) but it seems to me it's possible to pass any kind of argument to explorer.exe.
There's probably no immediate danger because it's very unlikely an outside attacker would guess you have this set up. Still, safe it's not.
I'd much rather have the server detect windows clients output \servername\path scheme for those and smb:// for everything else.
Not to mention, SMB isn't the only protocol that uses that syntax, so does any other filesystem such as WebDAV. Somewhat clever idea though, and I wish that smb:// worked too.
Related
All
is it possible to have file locked when opened by VSCode ?
any extensions?
so if I check file by handle64 from sysinternals, it will tell me something like
> handle64.exe -a c:\XXX.txt
code.exe pid: 123 type: File c:\XXX.txt
Windows solution would be fine, cross-platform would be the best
The Windows-specific file API (CreateFile) has a number of access and sharing options, so yes, technically it would be possible. But that doesn't mean it would be desirable. There are a number of use-cases where it is quite desirable to allow another process to read, change or delete a file while it is "open" (really visible) in vscode.
I put "open" in quotes because to achieve the behavior it currently has, vscode probably closes the file as soon as it's done reading it, intentionally avoiding the sort of behavior you seem to be asking for. Since your question deals with a specific solution, rather than the problem motivating you, it's hard to provide more detail.
Is it possible to use an Apple Script or a Unix executable to associate a file type with an app?
My problem is I'm using File Vault and it forgets previous associations (it's a well known bug so it seems). For instance, I like to use Flying Meat's Acorn for my graphics files rather than Preview. I can Cmd-I, change all, and while it sticks for one file the next time I reboot it's forgotten the association for everything else.
This has been driving me nuts for literally years. Any ideas?
I use Magic Launch and would highly recommend it. Not only can you associate programs with certain file types, but you can establish complex rules for when to use what app.
Or, to better answer your original question, you could try this:
defaults write com.apple.LaunchServices LSHandlers -array-add \
"<dict><key>LSHandlerContentType</key><string>public.png</string><key>LSHandlerRoleAll</key><string>com.flyingmeat.acorn</string></dict>"
I have an application which needs to be able to write to Any User/Current host preference files (which requires admin privileges per Preferences Utilities Reference) and also to enable/disable a launchd agent via its plist (writable only by root).
I'm using SFAuthorizationView to require users to authenticate as an admin before altering these values.
I'm trying to decide on the best way to do the actual altering of these values.
The cheap hackish option seems to be to use AuthorizationExecuteWithPrivileges() and mv or defaults, either via BLAuthentication or creating something similar myself. The downside to this is not getting the return value of whatever command line app I'm executing, plus some odd esoteric bugs I've encountered (such as getting a -60008 error in certain situations). This is strongly recommended against by Apple, obviously, but people do seem to do it and have some success with it.
The second most hackish option would seem to be the whole create a helper app with the suid bit set and the --self-repair option as discussed in various places. This seems possible, but like it's probably not much less trouble than the third option.
The third option is to create a fully fledged launchd daemon which will run as root and communicate with my application via a socket. This seems like a bit of overkill to read and write some plist files, but it's also possible I may find other uses for it down the road, and it wont be the only daemon for my application, so it doesn't seem unreasonable to just add another.
I'm thinking about modifying this sample code for my purposes.
My two questions are:
Does the launchd daemon option seem like the best route to go for this, or is there a much easier route I'm missing?
Has anybody else successfully used that code as a basis for something similar, and does anybody see any glaring issues with it I'm missing? I've used it successfully in a test app, but I'd be curious to hear you guys' opinion on it.
launchd is definitely the best and safest way to go: you’ll need an installer package to get your helper into place. Do be sure that your helper does and can do absolutely nothing except edit the files you wish to target.
No experience w/the code, but it’s based off of BetterAuthorizationSample, so that’s a nice start.
There's also the openauth API, which allows you to open files that require root privileges.
I'm trying to clear out the WinInet cache using Win32 API - by invalidating the cache entries, or deleting them (doesn't matter). I can't find any way to do this for the whole cache (other than iterating over each entry - example in C#, another in VB) - is this even possible?
Apparently, it is possible to (ab)use the Internet Options panel to clear the cache files by executing this:
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
Will try to call this as a DLL.
Source: http://www.vbforums.com/archive/index.php/t-440508.html , comment by technorobbo
I'm fairly certain doing the FindFirst/FindNextUrlCacheEntry() then DeleteUrlCacheEntry() is the only way to make sure it works across all versions of IE.
Alternatively you can use FindFirst/FindNextUrlCacheGroup() and DeleteUrlCacheGroup() with "CACHEGROUP_FLAG_FLUSHURL_ONDELETE" but you have to make sure you only delete what you want. For example, history, cookies and temporary internet files are all Cache groups.
Do not use the method: RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
This is unsupported by Microsoft and has been shown to break the cache and cause all sorts of unusual problems.
FTR: The exact meaning of the argument (8 above, means only Temporary Internet Files and not Cookies etc.) is explained e.g. on http://www.howtogeek.com/howto/windows/clear-ie7-browsing-history-from-the-command-line.
BTW: Unfortunately RunDll32 is asynchronous, which makes it not ideal for running before e.g. automated web tests. Would anybody have an idea either how to run this as a blocking call, or to how to programmatically find the exact directory name of the "Temporary Internet Files" directory so it can be polled until empty? Code it in C (need it in Java, could do JNI) is really the only option, huh? ;(
PS: How can one post a reply to an existing answer instead of starting a new answer on stackoverflow?
I have a bunch of files that I need to be able to transport and install quickly. My current method for doing so is moving a flash drive with a readme file of where stuff goes whenever I need to move stuff, which is rather inelegant and cumbersome.
My idea for a solution would be to write up a quick script to move files around that I could just click on. I've done some bash scripting before but batch scripting is a little odd to me. Does anyone have a good online reference guide I could use?
An alternative soulution I could accept would be a program that makes an installer for you, though I'm a bit against that as I would lose a lot of control. However, I'd be alright with it if it was extremely simple,
Sounds like robocopy tool is exactly what you need.
Very powerful replication command-line tool.
MS TechNet reference,
Wikipedia article about robocopy,
Full command switch guide,
Batch scripting guide.
I like to use VBscript for this kind of thing. The VBS engine is on every recent windows machine and the language is a little more like real programming than a batch script.
Also, if your installer grows to require WMI functions too, this becomes a piece of cake.